yii - Yii2 DetailView widget - access data with role -
this query using find user:
$model = user::find()->with('role')->where(['id' => $id])->one();
and detailview widget:
<?= detailview::widget([ 'model' => $model, 'attributes' => [ 'first_name', 'email:email', 'password', ], ]) ?>
i need access role name. how can this?
you write getrole in user model:
public function getrole() { $role = yii::app()->db->createcommand() ->select('itemname') ->from('authassignment') ->where('userid=:id', array(':id'=>$this->id)) ->queryscalar(); return $role; }
and use direct in widget $model->getrole()
hope solve problem.
Comments
Post a Comment