Dmytro Soltusyuk
Dmytro Soltusyuk

Reputation: 440

Why does nothing is loaded Yii 2

When I'm going to "view" view, nothing is loaded, even the default layout, which contains the HTML header and footer, so it displays nothing in source code.

Code from controllers:

    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]);
    }

Code from views:

"ART" VIEW:

<?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" VIEW:

<?php

/* @var $info */

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

var_dump($info);

?>

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

Upvotes: 1

Views: 76

Answers (1)

Bizley
Bizley

Reputation: 18021

You must return the result of render(), not just call it.

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

Also this

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

does nothing now. You must echo it so it will basically do the same that line below it does now. But better because it html-encodes the $composition['name'].

Upvotes: 6

Related Questions