为什么没有加载 Yii 2
Why does nothing is loaded Yii 2
当我要 "view" 查看时,没有加载任何内容,甚至是包含 HTML 页眉和页脚的默认布局,因此在源代码中不显示任何内容。
来自控制器的代码:
public function actionArt($type){
$compositions = Compositions::find()
->select(['id', 'name'])
->where('type' == $type)
->asArray()
->all();
return $this->render('art', ['compositions' => $compositions]);
}
public function actionView($id){
$info = Compositions::find()->where($id)->all();
$this->render('view', ['info' => $info]);
}
来自视图的代码:
"ART" 视图:
<?php
/* @var $compositions */
use yii\helpers\Html;
use yii\helpers\Url;
?>
<div class="site-art">
<?php foreach ($compositions as $composition){
Html::a(Html::encode($composition['name']), ['site/info', 'id' => $composition['id']]);
echo "<a href='" . Url::to(['site/view', 'id' => $composition['id']], true) . "'>{$composition['name']}</a><br>";
} ?>
</div>
"VIEW" 视图:
<?php
/* @var $info */
use yii\helpers\Html;
use yii\helpers\Url;
var_dump($info);
?>
<div class="site-info">
hwerasjdajsdajsk
</div>
您必须 return render()
的结果,而不仅仅是调用它。
return $this->render('view', ['info' => $info]);
还有这个
Html::a(Html::encode($composition['name']), ['site/info', 'id' => $composition['id']]);
现在什么都不做。你必须回显它,这样它基本上就会像现在下面那行一样。但更好,因为它 html-编码 $composition['name']
.
当我要 "view" 查看时,没有加载任何内容,甚至是包含 HTML 页眉和页脚的默认布局,因此在源代码中不显示任何内容。
来自控制器的代码:
public function actionArt($type){
$compositions = Compositions::find()
->select(['id', 'name'])
->where('type' == $type)
->asArray()
->all();
return $this->render('art', ['compositions' => $compositions]);
}
public function actionView($id){
$info = Compositions::find()->where($id)->all();
$this->render('view', ['info' => $info]);
}
来自视图的代码:
"ART" 视图:
<?php
/* @var $compositions */
use yii\helpers\Html;
use yii\helpers\Url;
?>
<div class="site-art">
<?php foreach ($compositions as $composition){
Html::a(Html::encode($composition['name']), ['site/info', 'id' => $composition['id']]);
echo "<a href='" . Url::to(['site/view', 'id' => $composition['id']], true) . "'>{$composition['name']}</a><br>";
} ?>
</div>
"VIEW" 视图:
<?php
/* @var $info */
use yii\helpers\Html;
use yii\helpers\Url;
var_dump($info);
?>
<div class="site-info">
hwerasjdajsdajsk
</div>
您必须 return render()
的结果,而不仅仅是调用它。
return $this->render('view', ['info' => $info]);
还有这个
Html::a(Html::encode($composition['name']), ['site/info', 'id' => $composition['id']]);
现在什么都不做。你必须回显它,这样它基本上就会像现在下面那行一样。但更好,因为它 html-编码 $composition['name']
.