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

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -