Yii2 theme baseurl

落花浮王杯 提交于 2019-12-24 07:38:38

问题


I'm trying to echo Yii2 theme base url using this official link.

<?php 
    $theme = $this->theme;
    echo $theme->baseUrl; // line 119
?>

but it return me this error:

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

Why this error? is it not possible to get Yii2 theme base url?


回答1:


seems that you component is not properly defined .. be sure you have a theme defined in you components section eg:

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


来源:https://stackoverflow.com/questions/38489044/yii2-theme-baseurl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!