0

Во вьюшке добавил 1 строку:

$this->title = $devArtView['title'];
$this->descr = $devArtView['descr']; // добавил эту строку, в массиве из БД она есть
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-about">
    <h1><?= Html::encode($this->title) ?></h1>
    <p>Это страница</p>
</div>

В layouts/main.php добавил <?= Html::encode($this->descr) ?> по аналогии с тем как выводится title

<head>
    <meta charset="<?= Yii::$app->charset ?>">
    <meta name="description" content="<?= Html::encode($this->descr) ?>">

    <?= Html::csrfMetaTags() ?>
    <title><?= Html::encode($this->title) ?></title>
    <?php $this->head() ?>

Ошибка: Setting unknown property: yii\web\View::descr Что я делаю не так?

1 ответ 1

1

У view нет свойства descr, отсюда и ошибка такая. Вам следует description выводит одним из 2-х способов

  1. В контроллере:

    \Yii::$app->view->registerMetaTag([ 'name' => 'description', 'content' => 'Description set inside controller', ]);

  2. Во view:

    $this->registerMetaTag([ 'name' => 'description', 'content' => 'Description set inside view', ]);

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.