Yii2主題整合?Yii2主題集成不起作用?
'view' => [
'theme' => [
'pathMap' => ['@app/views' => '@app/admin/views'],
'baseUrl' => '@web/admin',
],
],
Yii2主題整合?Yii2主題集成不起作用?
'view' => [
'theme' => [
'pathMap' => ['@app/views' => '@app/admin/views'],
'baseUrl' => '@web/admin',
],
],
在web目錄下創建「themes」目錄並在那裏創建主題。
然後將此代碼包含在您的主配置文件中。
'view' => [
'theme' => [
'baseUrl' => '@web/themes/yourthemename',
'pathMap' => [
'@app/views' => [
'@webroot/themes/yourthemename/views',
]
],
],
]
希望您使用的是高級模板
在後端文件夾添加一個文件夾主題
做出與主題名稱的子文件夾,請確保您有佈局文件夾,該文件夾中
即 新佈局文件夾路徑將是
後端/主題/ themefoldername /佈局
的文件夾中後端/配置/ main.php
'components' => [
'view' => [
'theme' => [
'basePath' => '@backend/themes/themefoldername',
'baseUrl' => '@backend/themes/themefoldername',
'pathMap' => [
'@backend/views' => '@backend/themes/themefoldername',
],
],
],...
,如果你想保持它在Web文件夾,你也可以做到這一點,但請確保您相應地更改路徑
在您的web.php文件中使用此代碼。
'view' => [
'theme' => [
'class' => yii\base\Theme::className(),
'basePath' => '@app/themes/themename',
'baseUrl' =>'@web/themes/themename',
],
],
這是我的代碼,我通常用於主題。您可以在參數文件中設置參數並在其中添加主題名稱,或直接在下面的代碼中添加主題名稱。
'view' => [
'theme' => [
'pathMap' => ['@app/views' => '@webroot/themes/themename/views'],
'baseUrl' => '@web/themes/themename',
],
],
如果您使用yii2基本然後在配置/ web.php寫這個
return [
'components' => [
'view' => [
'theme' => [
'basePath' => '@app/themes/basic',
'baseUrl' => '@web/themes/basic',
'pathMap' => [
'@app/views' => '@app/themes/basic',
],
],
],
],
];
我有adminlte主題這是找到供應商的文件夾,然後 在config/main.php補充說明:
'components' => [
'view' => [
'theme' => [
'pathMap' => [
'@app/views' => '@vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app'
],
],
],
在config/web.php下的基本安裝中添加組件塊下的代碼。
'components' => [
................
....................
'view' => [
'theme' => [
'pathMap' => [
'@app/views' => '@app/themes/mytheme',
'@app/modules' => '@app/themes/mytheme/modules',
],
'baseUrl' => '@web/themes/mytheme',
],
],
...........
]
在提前模板中,前端和後端主題集成有單獨的配置。
前端主題集成=> 「前端/配置/ main.php」 文件:
'components' => [
'view' => [
'theme' => [
'pathMap' => [
'@frontend/views' => '@themes/frontend/views', // need to // set alias first in your bootstrap.php file
],
],
],
],
後端主題集成=> 「後端/配置/ main.php」 文件:
'components' => [
'view' => [
'theme' => [
'pathMap' => [
'@backend/views' => '@themes/backend/views', // need to set // alias first in your "common/config/bootstrap.php" file
],
],
],
],
雖然編碼處理註釋和目錄路徑,並且不需要編寫baseUrl或basePath。
什麼問題,顯示你的組件代碼。你在做什麼,你的目標是什麼,我們無法想象你在做什麼...... – scaisEdge
http://stackoverflow.com/questions/25622565/yii2-theme-integration –
@Deepak Syal:如果它是任何安慰我發現Yii2的主題系統完全過於複雜,並不是非常基於慣例。每次都是頭痛的時候... –