• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Yii2 framework学习笔记(五) — 为后台更换皮肤

php 搞代码 4年前 (2022-01-04) 20次浏览 已收录 0个评论

为前台和后台做出区别,为backend换台AdminLTE的皮肤。

网上有现成的yii2的adminLTE插件,直接使用之。

在composer.json里的require节点添加如下内容

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

运行composer update安装代码。

安装完成后,将/vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app下的site/layouts两个文件夹内容复制覆盖/backend/views/下的同名文件夹。

稍微做些改动。

backend/views/layouts/main.php,根据里面的提示,把第一个if中的内容删除,完成后如下。

<?phpuse yii\helpers\Html;/* @var $this \yii\web\View *//* @var $content string */    if (class_exists('backend\assets\AppAsset')) {        backend\assets\AppAsset::register($this);    } else {        app\assets\AppAsset::register($this);    }    dmstr\web\AdminLteAsset::register($this);    $directoryAsset = Yii::$app->assetManager->getPublishedUrl('@vendor/almasaeed2010/adminlte/dist');    ?>    <?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(            'header.php',            ['directoryAsset' => $directoryAsset]        ) ?>        <?= $this->render(            'left.php',            ['directoryAsset' => $directoryAsset]        )        ?>        <?= $this->render(            'content.php',            ['content' => $content, 'directoryAsset' => $directoryAsset]        ) ?>    </div>    <?php $this->endBody() ?>    </body>    </html>    <?php $this->endPage() ?>

然后在backend/controllers/SiteController.php里,在aciontLogin里指向login需要使用的layout。

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 {            <p style="color:transparent">来源gao!%daima.com搞$代*!码网</p>return $this->render('login', [                'model' => $model,            ]);        }    }

完成后效果如下。

以上就是Yii2 framework学习笔记(五) — 为后台更换皮肤的内容,更多相关内容请关注搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Yii2 framework学习笔记(五) — 为后台更换皮肤

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址