yii 为什么什么都不装呢

ht4b089n  于 2022-11-09  发布在  其他
关注(0)|答案(1)|浏览(112)

当我转到“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]);
    }

检视中的程式码:
“艺术”视图:

<?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>

“查看”视图:

<?php

/* @var $info */

use yii\helpers\Html;
use yii\helpers\Url;

var_dump($info);

?>

<div class="site-info">
    hwerasjdajsdajsk
</div>
yqkkidmi

yqkkidmi1#

您必须返回render()的结果,而不仅仅是调用它。

return $this->render('view', ['info' => $info]);

还这

Html::a(Html::encode($composition['name']), ['site/info', 'id' => $composition['id']]);

现在什么都不做。你必须回显它,这样它基本上会做下面那行现在做的事情。但是更好,因为它对$composition['name']进行了html编码。

相关问题