search
Homephp教程PHP开发Yii2 framework study notes (5) -- changing the skin for the backend

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.

<?php
use yii\helpers\Html;

/* @var $this \yii\web\View */
/* @var $content string */

    if (class_exists(&#39;backend\assets\AppAsset&#39;)) {
        backend\assets\AppAsset::register($this);
    } else {
        app\assets\AppAsset::register($this);
    }

    dmstr\web\AdminLteAsset::register($this);

    $directoryAsset = Yii::$app->assetManager->getPublishedUrl(&#39;@vendor/almasaeed2010/adminlte/dist&#39;);
    ?>
    <?php $this->beginPage() ?>
    <!DOCTYPE html>
    <html lang="<?= Yii::$app->language ?>">
    <head>
        <meta charset="<?= Yii::$app->charset ?>"/>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <?= Html::csrfMetaTags() ?>
        <title><?= Html::encode($this->title) ?></title>
        <?php $this->head() ?>
    </head>
    <body class="hold-transition skin-blue sidebar-mini">
    <?php $this->beginBody() ?>
    <div>

        <?= $this->render(
            &#39;header.php&#39;,
            [&#39;directoryAsset&#39; => $directoryAsset]
        ) ?>

        <?= $this->render(
            &#39;left.php&#39;,
            [&#39;directoryAsset&#39; => $directoryAsset]
        )
        ?>

        <?= $this->render(
            &#39;content.php&#39;,
            [&#39;content&#39; => $content, &#39;directoryAsset&#39; => $directoryAsset]
        ) ?>

    </div>

    <?php $this->endBody() ?>
    </body>
    </html>
    <?php $this->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 = &#39;//main-login&#39;;
        $model = new LoginForm();
        if ($model->load(Yii::$app->request->post()) && $model->login()) {
            return $this->goBack();
        } else {
            return $this->render(&#39;login&#39;, [
                &#39;model&#39; => $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 (www.php.cn)!


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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.