1. Create a directory: \backend\views\themes\default, specifying the base directory that contains the theme assets (CSS, JS, images, etc.), as shown in Figure 1

2. Copy all files under the directory: \backend\views\ (excluding themes), as shown in Figure 2

3. Paste them into the directory: \backend\views\themes\default\. The files have been copied successfully, as shown in Figure 3

4. Configure the [[yii\base\View::theme|theme]] property of the view application component, as shown in Figure 4
'components' => [
'view' => [
'theme' => [
'basePath' => '@app/views/themes/default',
'baseUrl' => '@web/views/themes/default',
'pathMap' => [
'@app/views' => '@app/views/themes/default',
],
],
],
],
![Configure the [[yii\base\View::theme|theme]] property of the view application component](https://media.shuijingwanwq.com/2017/11/4-2.png)
5. Configure the Gii template files, setting the theme to: default, as shown in Figure 5
if (YII_ENV_DEV) {
$config['modules']['gii'] = [
'class' => yii\gii\Module::class,
'generators' => [
'crud' => [
'class' => yii\gii\generators\crud\Generator::class,
'templates' => [
'yii2-starter-kit' => Yii::getAlias('@backend/views/themes/default/_gii/templates')
],
'template' => 'yii2-starter-kit',
'messageCategory' => 'backend'
]
]
];
}

6. Theme the module, for example: i18n. Create a directory: \backend\modules\i18n\views\themes\default, as shown in Figure 6

7. Copy all files under the directory: \backend\modules\i18n\views\ (excluding themes), as shown in Figure 7

8. Paste them into the directory: \backend\modules\i18n\views\themes\default\. The files have been copied successfully, as shown in Figure 8

9. Configure the [[yii\base\View::theme|theme]] property of the view application component, as shown in Figure 9
'view' => [
'theme' => [
'basePath' => '@app/views/themes/default',
'baseUrl' => '@web/views/themes/default',
'pathMap' => [
'@app/views' => '@app/views/themes/default',
'@app/modules/i18n/views' => '@app/modules/i18n/views/themes/default',
],
],
],
![Configure the [[yii\base\View::theme|theme]] property of the view application component](https://media.shuijingwanwq.com/2017/11/9.png)
10. Access the [[yii\base\Theme]] object via the [[yii\base\View::theme]] property. Edit: \backend\views\themes\default\sign-in\login.php, as shown in Figure 10
$theme = $this->theme;
print_r($theme);
exit;
![Access the [[yii\base\Theme]] object via the [[yii\base\View::theme]] property. Edit: \backend\views\themes\default\sign-in\login.php](https://media.shuijingwanwq.com/2017/11/10.png)
11. The printed object, as shown in Figure 11
yii\base\Theme Object
(
[pathMap] => Array
(
[@app/views] => @app/views/themes/default
[@app/modules/i18n/views] => @app/modules/i18n/views/themes/default
)
[_baseUrl:yii\base\Theme:private] => /views/themes/default
[_basePath:yii\base\Theme:private] => E:\wwwroot\cmcp\backend/views/themes/default
[_events:yii\base\Component:private] => Array
(
)
[_behaviors:yii\base\Component:private] =>
)

12. Set the theme name to: default in .env, as shown in Figure 12
# Themes
# ----
BACKEND_THEME = default

13. Set the theme-related aliases. Edit: \backend\config\bootstrap.php to define the aliases, as shown in Figure 13
/**
* Setting theme aliases
*/
Yii::setAlias('@themePath', '@backend/web/themes/' . env('BACKEND_THEME'));
Yii::setAlias('@themeUrl', '@backendUrl/themes/' . env('BACKEND_THEME'));

14. Adjust the settings from step 5, as shown in Figure 14
if (YII_ENV_DEV) {
$config['modules']['gii'] = [
'class' => yii\gii\Module::class,
'generators' => [
'crud' => [
'class' => yii\gii\generators\crud\Generator::class,
'templates' => [
'yii2-starter-kit' => Yii::getAlias('@backend/views/themes/' . env('BACKEND_THEME') . '/_gii/templates')
],
'template' => 'yii2-starter-kit',
'messageCategory' => 'backend'
]
]
];
}

15. Adjust the settings from step 9, as shown in Figure 15
'view' => [
'theme' => [
'basePath' => '@app/views/themes/' . env('BACKEND_THEME'),
'baseUrl' => '@web/views/themes/' . env('BACKEND_THEME'),
'pathMap' => [
'@app/views' => '@app/views/themes/' . env('BACKEND_THEME'),
'@app/modules/i18n/views' => '@app/modules/i18n/views/themes/' . env('BACKEND_THEME'),
],
],
],

16. Create a directory: \backend\web\themes\default, specifying the base directory that contains the theme assets (CSS, JS, images, etc.), as shown in Figure 16

17. Copy the directories (css, img, js) under: \backend\web\, as shown in Figure 17

18. Paste them into the directory: \backend\web\themes\default\. The files have been copied successfully, as shown in Figure 18

19. Redefine the asset bundle based on the theme. Edit: \backend\assets\BackendAsset.php, as shown in Figure 19
public $basePath = '@themePath';
public $baseUrl = '@themeUrl';

20. View the source code of the login page. The biggest change is the included CSS/JS files, whose paths are absolute, as shown in Figure 20

