2017-05-21 4 views
0

セッション(first_name、last_name、phone、email)のデータを取得しようとしています。ビューファイルにデータを表示する方法

public function actionIndex(){ 
    $query = User::findOne(Yii::$app->session['user']['id']); 

    return $this->render('index', ['query' => $query]); 
} 

ビューファイルでDetailView :: Widgetを使用しようとしましたが、氷が切れていません。 このデータをビューファイルに一覧表示する方法を教えてもらえますか?

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 
    ], 
]); 

答えて

0
$this->render('index', ['model' => $query]); } 

modelへの鍵**query**変更。またはビューの変更$model$query

ユーザーがログインして、あなたが使用できるアプリ/モデル/ユーザモデルを使用している場合:

$user = \Yii::$app->user->identity; 
echo $user->last_name; 
echo $user->id; 

にVIEW:

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 
    ], 
]); 
+0

$ユーザ= \のYii :: $ APP-> USER- >同一性; echo $ user-> last_name; echo $ user-> id; このコードはどこにありますか? – user8042876

関連する問題