我第一次使用yii2主题。我通过以下链接看到了要在yii2中实现的主题:Yii2 theme factory
根据文档,我下载了主题并安装了它。我创建了一个themes
文件夹,放置了我的主题。
我做了很多:
在config / web.php文件中
'components' => [
'view' => [
'theme' => [
'pathMap' => ['@app/views' => '.@wwwroot/themes/themes'],
'baseUrl' => '@www/themes/themes'
]
],
],
但是,我遇到了这种错误:
An Error occurred while handling another error:
exception 'yii\base\InvalidParamException' with message 'Invalid path alias: @www/themes/themes' in /var/www/html/scrum_tool/vendor/yiisoft/yii2/BaseYii.php:152
Stack trace:
#0 /var/www/html/scrum_tool/vendor/yiisoft/yii2/base/Theme.php(99): yii\BaseYii::getAlias('@www/themes/the...')
#1 /var/www/html/scrum_tool/vendor/yiisoft/yii2/base/Component.php(169): yii\base\Theme->setBaseUrl('@www/themes/the...')
#2 /var/www/html/scrum_tool/vendor/yiisoft/yii2/BaseYii.php(518): yii\base\Component->__set('baseUrl', '@www/themes/the...')
#3 /var/www/html/scrum_tool/vendor/yiisoft/yii2/base/Object.php(105): yii\BaseYii::configure(Object(yii\base\Theme), Array)
#4 [internal function]: yii\base\Object->__construct(Array)
#5 /var/www/html/scrum_tool/vendor/yiisoft/yii2/di/Container.php(372): ReflectionClass->newInstanceArgs(Array)
#6 /var/www/html/scrum_tool/vendor/yiisoft/yii2/di/Container.php(151): yii\di\Container->build('yii\\base\\Theme', Array, Array)
#7 /var/www/html/scrum_tool/vendor/yiisoft/yii2/BaseYii.php(344): yii\di\Container->get('yii\\base\\Theme', Array, Array)
#8 /var/www/html/scrum_tool/vendor/yiisoft/yii2/base/View.php(116): yii\BaseYii::createObject(Array)
#9 /var/www/html/scrum_tool/vendor/yiisoft/yii2/base/Object.php(107): yii\base\View->init()
#10 [internal function]: yii\base\Object->__construct(Array)
#11 /var/www/html/scrum_tool/vendor/yiisoft/yii2/di/Container.php(372): ReflectionClass->newInstanceArgs(Array)
#12 /var/www/html/scrum_tool/vendor/yiisoft/yii2/di/Container.php(151): yii\di\Container->build('yii\\web\\View', Array, Array)
#13 /var/www/html/scrum_tool/vendor/yiisoft/yii2/BaseYii.php(344): yii\di\Container->get('yii\\web\\View', Array, Array)
#14 /var/www/html/scrum_tool/vendor/yiisoft/yii2/di/ServiceLocator.php(133): yii\BaseYii::createObject(Array)
#15 /var/www/html/scrum_tool/vendor/yiisoft/yii2/base/Application.php(554): yii\di\ServiceLocator->get('view')
#16 /var/www/html/scrum_tool/vendor/yiisoft/yii2/web/ErrorHandler.php(228): yii\base\Application->getView()
#17 /var/www/html/scrum_tool/vendor/yiisoft/yii2/web/ErrorHandler.php(99): yii\web\ErrorHandler->renderFile('@yii/views/erro...', Array)
#18 /var/www/html/scrum_tool/vendor/yiisoft/yii2/base/ErrorHandler.php(101): yii\web\ErrorHandler->renderException(Object(yii\base\InvalidParamException))
#19 [internal function]: yii\base\ErrorHandler->handleException(Object(yii\base\InvalidParamException))
#20 {main}
Previous exception:
exception 'yii\base\InvalidParamException' with message 'Invalid path alias: @www/themes/themes' in /var/www/html/scrum_tool/vendor/yiisoft/yii2/BaseYii.php:152
Stack trace:
#0 /var/www/html/scrum_tool/vendor/yiisoft/yii2/base/Theme.php(99): yii\BaseYii::getAlias('@www/themes/the...')
#1 /var/www/html/scrum_tool/vendor/yiisoft/yii2/base/Component.php(169): yii\base\Theme->setBaseUrl('@www/themes/the...')
#2 /var/www/html/scrum_tool/vendor/yiisoft/yii2/BaseYii.php(518): yii\base\Component->__set('baseUrl', '@www/themes/the...')
#3 /var/www/html/scrum_tool/vendor/yiisoft/yii2/base/Object.php(105): yii\BaseYii::configure(Object(yii\base\Theme), Array)
#4 [internal function]: yii\base\Object->__construct(Array)
#5 /var/www/html/scrum_tool/vendor/yiisoft/yii2/di/Container.php(372): ReflectionClass->newInstanceArgs(Array)
#6 /var/www/html/scrum_tool/vendor/yiisoft/yii2/di/Container.php(151): yii\di\Container->build('yii\\base\\Theme', Array, Array)
#7 /var/www/html/scrum_tool/vendor/yiisoft/yii2/BaseYii.php(344): yii\di\Container->get('yii\\base\\Theme', Array, Array)
#8 /var/www/html/scrum_tool/vendor/yiisoft/yii2/base/View.php(116): yii\BaseYii::createObject(Array)
#9 /var/www/html/scrum_tool/vendor/yiisoft/yii2/base/Object.php(107): yii\base\View->init()
#10 [internal function]: yii\base\Object->__construct(Array)
#11 /var/www/html/scrum_tool/vendor/yiisoft/yii2/di/Container.php(372): ReflectionClass->newInstanceArgs(Array)
#12 /var/www/html/scrum_tool/vendor/yiisoft/yii2/di/Container.php(151): yii\di\Container->build('yii\\web\\View', Array, Array)
#13 /var/www/html/scrum_tool/vendor/yiisoft/yii2/BaseYii.php(344): yii\di\Container->get('yii\\web\\View', Array, Array)
#14 /var/www/html/scrum_tool/vendor/yiisoft/yii2/di/ServiceLocator.php(133): yii\BaseYii::createObject(Array)
#15 /var/www/html/scrum_tool/vendor/yiisoft/yii2/base/Application.php(554): yii\di\ServiceLocator->get('view')
#16 /var/www/html/scrum_tool/vendor/yiisoft/yii2-debug/Module.php(129): yii\base\Application->getView()
#17 [internal function]: yii\debug\Module->yii\debug\{closure}(Object(yii\base\Event))
#18 /var/www/html/scrum_tool/vendor/yiisoft/yii2/base/Component.php(541): call_user_func(Object(Closure), Object(yii\base\Event))
#19 /var/www/html/scrum_tool/vendor/yiisoft/yii2/base/Application.php(372): yii\base\Component->trigger('beforeRequest')
#20 /var/www/html/scrum_tool/index.php(13): yii\base\Application->run()
#21 {main}
答案 0 :(得分:4)
看起来@wwwroot
不是有效路径。
如果您使用的是基本应用,请尝试此操作:
'components' => [
'view' => [
'theme' => [
'pathMap' => ['@app/views' => '@app/themes/mytheme'],
'baseUrl' => '@web/themePath',
],
],
],
更多信息here
答案 1 :(得分:0)
尝试这样的事情
'view' => [
'theme' => [
'basePath' => '@wwwroot/themes/themes',
'pathMap' => ['@app/views' => '@wwwroot/themes/themes'],
'baseUrl' => '@www/themes/themes'
],
],
并且一个常见的错误就是使用它来布局文件夹而不是视图文件夹。请注意这一点,如果你想要覆盖布局,请在@ wwwroot / themes / themes中创建一个布局文件夹。