Home  >  Article  >  php教程  >  Yii2 framework study notes (5) -- changing the skin for the backend

Yii2 framework study notes (5) -- changing the skin for the backend

黄舟
黄舟Original
2016-12-30 09:53:361597browse

Make a distinction between the frontend and the backend, and change the AdminLTE skin for the backend.

There is a ready-made adminLTE plug-in for yii2 on the Internet, use it directly.

Add the following content to the require node in composer.json

"require": {
         ...
         "dmstr/yii2-adminlte-asset": "2.*",
         ...
    },

Run the composer update installation code.

After the installation is complete, copy the contents of the site/layouts folders under /vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app to overwrite those under /backend/views/ folder with the same name.

Make some slight changes.

backend/views/layouts/main.php, according to the prompts inside, delete the content in the first if, as shown below.

assetManager->getPublishedUrl('@vendor/almasaeed2010/adminlte/dist');
    ?>
    beginPage() ?>
    
    
    
        
        
        
        <?= Html::encode($this->title) ?>
        head() ?>
    
beginBody() ?>
render( 'header.php', ['directoryAsset' => $directoryAsset] ) ?> render( 'left.php', ['directoryAsset' => $directoryAsset] ) ?> render( 'content.php', ['content' => $content, 'directoryAsset' => $directoryAsset] ) ?>
endBody() ?> endPage() ?>

Then in backend/controllers/SiteController.php, point to the layout that needs to be used for login in aiontLogin.

public function actionLogin()
    {
        if (!\Yii::$app->user->isGuest) {
            return $this->goHome();
        }
        // add this line to use the right layout
        $this->layout = '//main-login';
        $model = new LoginForm();
        if ($model->load(Yii::$app->request->post()) && $model->login()) {
            return $this->goBack();
        } else {
            return $this->render('login', [
                'model' => $model,
            ]);
        }
    }

The finished effect is as follows.

Yii2 framework study notes (5) -- changing the skin for the backend

Yii2 framework study notes (5) -- changing the skin for the backend

The above are the Yii2 framework study notes (5) - the content of changing the skin for the background. For more related content, please pay attention to PHP Chinese Net (m.sbmmt.com)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn