用于呈现索引页的控制器操作
public function actionIndex()
{
$posts = Posts::find()->all();
$user = User::find()->all;
return $this->render('index', [
'posts' => $posts,
'user' => $user
]);
}
查看:
<? foreach ($posts as $post){?>
<div class="well">
<h5><?=$user[$post->user_id-1]->login ?></h5>
<?=$post->text ?>
</div>
<?} ?>
显示帖子文本但用户不登录。为什么? var_dump($ users)什么都没显示。我查了一下这张桌子。用户表中有一些记录。
答案 0 :(得分:0)
public function actionIndex()
{
$posts = Posts::find()->all();
$user = User::find()->all();
return $this->render('index', [
'posts' => $posts,
'user' => $user
]);
}
使用User::find()->all();
不 User::find()->all;