当我要“查看”视图时,没有加载任何内容,甚至是包含 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]);
}
Run Code Online (Sandbox Code Playgroud)
视图中的代码:
“艺术”视图:
<?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>
Run Code Online (Sandbox Code Playgroud)
“查看”查看:
<?php
/* @var $info */
use yii\helpers\Html;
use yii\helpers\Url;
var_dump($info);
?>
<div class="site-info">
hwerasjdajsdajsk
</div>
Run Code Online (Sandbox Code Playgroud)
您必须返回的结果render(),而不仅仅是调用它。
return $this->render('view', ['info' => $info]);
Run Code Online (Sandbox Code Playgroud)
还有这个
Html::a(Html::encode($composition['name']), ['site/info', 'id' => $composition['id']]);
Run Code Online (Sandbox Code Playgroud)
现在什么都不做。你必须回应它,所以它基本上会和它现在下面的那一行做同样的事情。但更好,因为它对$composition['name'].
| 归档时间: |
|
| 查看次数: |
60 次 |
| 最近记录: |