Skip to content

Instantly share code, notes, and snippets.

@evercode1
Created December 31, 2014 07:14
Show Gist options
  • Save evercode1/22a305bdf1e85a4967df to your computer and use it in GitHub Desktop.
Save evercode1/22a305bdf1e85a4967df to your computer and use it in GitHub Desktop.
User Relationships to Role
/**
* get role relationship
*
*/
public function getRole()
{
return $this->hasOne(Role::className(), ['role_value' => 'role_id']);
}
/**
* get role name
*
*/
public function getRoleName()
{
return $this->role ? $this->role->role_name : '- no role -';
}
/**
* get list of roles for dropdown
*/
public static function getRoleList()
{
$droptions = Role::find()->asArray()->all();
return ArrayHelper::map($droptions, 'role_value', 'role_name');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment