I am trying to get data of a user(first_name, last_name, phone, email) from the session.
public function actionIndex(){
$query = User::findOne(Yii::$app->session['user']['id']);
return $this->render('index', ['query' => $query]);
}
I tried using the DetailView::Widget in the view file but it's not cutting any ice. Can someone help me how to display this data in view file in a list?
Viewfile:
echo DetailView::widget([
'model' => $model,
'attributes' => [
'title', // title attribute (in plain text)
'description:html', // description attribute in HTML
[ // the owner name of the model
'label' => 'Owner',
'value' => $model->user->last_name,
],
//'created_at:datetime', // creation date formatted as datetime
],
]);
$this->render('index', ['model' => $query]); }
Change key **query**
to model
. Or in view change $model
to $query
.
If user is logged, and you use app/model/user model you can use:
$user = \Yii::$app->user->identity;
echo $user->last_name;
echo $user->id;
Viewfile:
echo DetailView::widget([
'model' => $model,
'attributes' => [
'title', // title attribute (in plain text)
'description:html', // description attribute in HTML
[ // the owner name of the model
'label' => 'Owner',
'value' => \Yii::$app->user->identity->last_name,
],
//'created_at:datetime', // creation date formatted as datetime
],
]);