Reputation: 1654
I am trying to render two models in the actionView method, but without result. Checked some answers on previous questions and it seems my method is OK, but still do not work.
This is what a made for method view:
public function actionView($id)
{
$postModel = Post::find()->where(['post_id' => $id])->one();
$currUser = BlogUser::find()->where(['id' => $postModel->user_id])->one();
return $this->render('view', [
'model' => $this->findModel($id),
'author' => $currUser
]);
}
and my view page:
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model app\models\Post */
//$this->title = $model->title;
//$this->params['breadcrumbs'][] = ['label' => 'Posts', 'url' => ['index']];
//$this->params['breadcrumbs'][] = $this->title;
?>
<div class="post-view">
<div class="content">
<div class="row">
<div class="col-md-3">
<?= $model->content;
$author->username;
?>
</div>
</div>
</div>
</div>
It tells that the author variable is undefined but cannot realize why when i render it in the action. Will appreciate every advice! Thank you!
Upvotes: 0
Views: 656
Reputation: 5456
Try using:
<div class="post-view">
<div class="content">
<div class="row">
<div class="col-md-3">
<?= $model->content; ?>
<?= $author->username; ?>
</div>
</div>
</div>
</div>
Upvotes: 2