The example in this article describes how to create a multi-interface theme (Theme) in Yii2. Share it with everyone for your reference, the details are as follows:
The design of the Yii2 interface theme is generally consistent with Yii1. The interface theme (Theme) is also managed by the view;
2. View files and web resources are separated in the directory (in the application template, they correspond to the views and web directories respectively)
Using the advanced application template as For example,
First create a themes/{your theme name} directory in the frontend/views and frontend/web directories, such as themes/basic.
Then in the application configuration, modify the configuration as follows:
'view' => [ 'theme' => [ 'pathMap' => ['@frontend/views' => '@frontend/themes/basic/views'], 'baseUrl' => '@web/themes/basic', ], ],
Modify the $baseUrl variable of AppAssets to:
class AppAsset extends AssetBundle { public $basePath = '@webroot'; public $baseUrl = '@web/themes/basic'; ... }
Finally create a page under views/themes/basic (such as site.php ), create resources (such as css/site.css) under web/themes/basic.
In this way, you can use this newly created interface theme. When rendering the view, Yii2 will first look for the theme directory you defined, and then look for the default directory.
To create a multi-interface theme, just follow the same steps to add a new theme in the themes directory, such as themes/advanced.
If you want to explicitly reference the resources under an interface theme in the view file, you can use $this->theme->baseUrl...
I hope this article will be helpful to everyone's PHP program design based on the Yii framework. helped.
For more articles on how to create multi-interface themes (Theme) with Yii2, please pay attention to the PHP Chinese website!