问题
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
- 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