Yii2 主题 baseurl [英] Yii2 theme baseurl

查看:36
本文介绍了Yii2 主题 baseurl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用这个 官方链接来回应 Yii2 主题基础网址.

theme;echo $theme->baseUrl;//第 119 行?>

但它返回给我这个错误:

<块引用>

PHP 注意 – yii\base\ErrorException 试图获取的属性非对象

  1. 在 E:\wamp\www\yii2-app\frontend\views\site\index.php 第 119 行

为什么会出现这个错误?Yii2 主题基础网址无法获取吗?

解决方案

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

<块引用>

 返回 ['组件' =>['视图' =>['主题' =>['basePath' =>'@app/主题/基本','baseUrl' =>'@web/主题/基本','路径映射' =>['@app/views' =>'@app/主题/基本',],],],],];

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?

解决方案

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',
                  ],
              ],
          ],
      ],
];

这篇关于Yii2 主题 baseurl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆