yii2-basic后台管理功能开发之一:引入模板

本文介绍如何使用Yii2框架中的Gii工具生成admin模块,并整合AdminLTE2模板以快速搭建具备图片上传和富文本编辑等功能的后台管理系统。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前景:哎没想到用php的yii2框架写了官网……自己选择的框架,跪着也要码完,当年用yii2-basic搭建了官网,原是想偷懒的,没想到还要写后台。。。。

需求:实现一个可编辑页面图片及新闻内容的后台管理系统

分析:粗略来看我们需要实现一下功能点

  • 管理员登陆(官方前台木有登陆--仅仅是公司介绍的pages)
  • 菜单栏
  • 图片上传
  • 富文本编辑器

解决方案:

  • 寻找靠谱后台管理模板(暂定AdminLTE2)
  • 寻找靠谱富文本编辑器(暂定ueditor)

关于作者:菜鸟,对php,yii2处于探索阶段。所以如有错误,请大家指出[抱拳]。

本篇文章主要内容:

  • 使用Gii工具生成后台模块admin
  • 将AdminLTE整合至admin模块中

1、创建模块

  访问http://localhost:8080/gii

  选择Module Generator,输入新建模块信息,我取名admin

  模块文件新建好了,我们需要去配置文件app/config/web.php中注册admin模块。在config中添加‘modules’

$config = [
    'modules' => [
        'admin' => [
            'class' => 'app\modules\admin\Admin',
        ],
    ],
]

  访问http://localhost:8080/index.php?r=admin/default/index 应该就可以访问到admin模块了。

  如果gii页面没有权限访问或者不能访问,那么需要去配置gii模块,也在app/config/web.php中。

 

2、将AdminLTE2引入到admin的布局

  该部分内容参考学习以下网页内容

http://www.yiiframework.com/extension/yii2-adminlte-asset/

  不熟悉的可以移步至官网查看

  不过已经有热心的小伙伴整合了yii2版本的AdminLTE,详见以上链接。

  引入方法如下:

  1、通过composer下载yii2-adminlte-asset包

composer require dmstr/yii2-adminlte-asset "2.*"

  2、将vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app目录下的layouts 整体复制到 admin/views/文件夹下。

  3、配置view

$config = [
    'modules' => [
        'admin' => [
            'class' => 'app\modules\admin\Admin',
        ],
        'view' => [
            'theme' => [
                'pathMap' => [
                    '@app/views' => '@vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app'
                ],
            ],
        ],
    ],
]

  4、将admin的layouts指向yii2-adminlte布局

  在admin/controllers/DefaultController.php中设置:

public  $layout = '../layouts/main';

  就可以啦~~~

 

转载于:https://www.cnblogs.com/perallina/p/5819038.html

基于Yii 框架开发的博客!用于学习YII。 DLFBLOG 1.0 基于Yii 框架开发的博客! Quick start Clone the repo, git clone git://github.com/windsdeng/dlfblog.git, or download the latest release. Bug tracker Have a bug? Please create an issue here on GitHub! Also, when filing please make sure you're familiar with necolas's guidelines. thanks! <3 https://github.com/windsdeng/dlfblog/issues DLFBLOG DEMO http://demo.dlf5.net QQ交流群 1、185207750 Author WindsDeng http://www.dlf5.com https://github.com/windsdeng http://www.weibo.com/windsdeng http://1.t.qq.com/fz-iloveyou Copyright and license The DLFBLOG is free software. It is released under the terms of the following BSD License. Copyright © 2012 by DLF5.NET (http://www.dlf5.net) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of DLF5.NET nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 标签:dlfblog
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值