The example in this article describes how YII2 creates a multiple-interface theme (Theme). Share to everyone for your reference, specific as follows:
The design of the Yii2 interface theme is generally consistent with yii1.x, which differs in two places:
1. Because Yii2 introduces a separate view class, the interface theme (Theme) is also managed by the view;
2. View files and Web resources are separated from the directory (in the application template, respectively, for views and web directories)
Take the advanced application template for example,
First, create a themes/{your theme name} directory under 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 ',
],
],
The $baseurl variable for modifying appassets is:
Class Appasset extends Assetbundle
{public
$basePath = ' @webroot ';
Public $baseUrl = ' @web/themes/basic ';
...
}
Finally, create a page (such as site.php) under Views/themes/basic to create a resource (such as CSS/SITE.CSS) under Web/themes/basic.
In this way, you can use this new interface theme, when rendering the view, YII2 will first look up your defined theme directory, and then look for the default directory.
To create a multiple-interface theme, just follow the same steps to add a new theme, such as themes/advanced, to the themes directory.
If you want to explicitly reference resources under an interface theme in a view file, you can use the $this->theme->baseurl ...
For more information on YII-related content, readers who are interested in this site can view the topics: Introduction to YII Framework and summary of common skills, "Summary of PHP Excellent development framework", "Smarty Template Introductory Course", "Introduction to PHP object-oriented programming", "PHP string" Summary of Usage , "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design based on the YII framework.