一、config main.php文件中components添加配置:

'view'=>[
    'theme'=>[
        'basePath'=>'@app/themes/basic',
        'baseUrl'=>'@web/themes/exception',
        'pathMap'=>[
            '@app/views'=>[
                '@app/themes/exception',
                '@app/themes/basic'
            ],
            '@app/modules'=>'@app/themes/basic/modules',
            '@app/modules'=>'@app/themes/basic/widgets',
        ]
    ]
],

二、视图文件中使用方法:

$this->theme->getUrl('images/hire.png');
$this->theme->getPath('images/hire.png');

//主题配置
//$arr[0]= '@app/themes/'.Yii::$app->params['web']['WEB_THEME'];
$arr[0]= '@app/themes/'.'exception';
Yii::$app->view->theme->pathMap['@app/views']=$arr;

上一篇:Yii2学习笔记十九:Formatter格式化(转载)

下一篇:Yii2学习笔记二十一:Yii2 别名(Aliases)使用