Yii2 主题 baseurl

Yii2 theme baseurl

我正在尝试使用这个 official link.

来回应 Yii2 主题库 url
<?php 
    $theme = $this->theme;
    echo $theme->baseUrl; // line 119
?>

但是 return 我这个 错误:

PHP Notice – yii\base\ErrorException Trying to get property of non-object

  1. in E:\wamp\www\yii2-app\frontend\views\site\index.php at line 119

为什么会出现这个错误?是不是无法获得 Yii2 主题库 url?

似乎您的组件没有正确定义..确保您在组件部分定义了主题,例如:

  return [
      'components' => [
          'view' => [
              'theme' => [
                  'basePath' => '@app/themes/basic',
                  'baseUrl' => '@web/themes/basic',
                  'pathMap' => [
                      '@app/views' => '@app/themes/basic',
                  ],
              ],
          ],
      ],
];