Code Monkey home page Code Monkey logo

yii2admin's Introduction

成型后的系统包括文章、商城、单页、广告、购物车、订单、标签、评论、推荐位、艾特@、消息、支付和回调、后台rbac、后台行为日志、数据可视化、配置管理等、前台用户中心、会员积分等功能。关注的朋友可以先给个Star。。

特别说明,这是一个学习型的项目(注释会尽量详细,尽量将yii2提供的大部分功能都用一遍)。有什么建议可以联系我:[email protected]

如遇bug请告诉作者哦,花你一分钟时间就可以让项目更易使用.^_^.

github : https://github.com/e282486518/yii2admin

oschina : http://git.oschina.net/ccdream/yii2admin (国内可以下载这个)

交流:http://www.yiichina.com/code/1052 (遇到bug不愿发邮件的可以贴到这里)

全站打包:https://share.weiyun.com/92c0d3e52e99d94255e001c76689b0a1 (不定期更新,安装出错的朋友可以试试这个)

一、开发基础说明

  • 系统配置文件为.env文件。

  • gii生成的模型统一放在 common\modelsgii下,模型统一继承 common\core\BaseActiveRecord 方便扩展yii核心;

  • 所有公共模型放在 common\models 下,并继承 common\modelsgii 对应模型;

  • 所有表单模型都继承 common\core\BaseModel

  • 所有控制器都继承 common\core\Controller ,每个应用下面应有一个BaseController控制器,做为该应用的父控制器,方便做一些公共操作;

  • 所有 自定义助手函数都放在 common\helpers\ 且方法都未static方法;

  • 公共别名在common/config/bootstarp.php中定义,使用Yii::getAlias()访问;

  • 超级管理员在\backend\comfig\params.php的“admin”项中定义其UID,超级管理员不需要进行RBAC权限检查;

  • 关于后台中的配置项目,实际是经过转化后(通常在BaseController控制器的init构造函数中转化),变为Yii::$app->params['web']中;

Yii::$app->params['web'] = Config::lists();
  • 在后台的BaseController中有一些通用的方法,例如saveRow(添加或编辑一行)、delRow(删除一行)、error(错误提示)、success(成功提示)、setForward(标记当前列表url,通常在列表中标记)、getForward(获取列表url方便跳转,通常结合error或success使用);

  • 多语言配置在/common/config/main.php中“i18n”项中,源语言设置的是中文,具体可自行查看;

  • 后台项目的js和css资源文件放在/common/metronic中;

  • 由于我使用的是模板自带的jQuery和bootstrap,所以我再后台main.php的assetManager项中清空了系统自带的jQuery和bootstrap,为了模板全局的js/css放在其他插件的前面,这里我设置了yii\web\JqueryAsset依赖backend\assets\AppAsset,这里要注意循环依赖的问题;

  • RBAC权限系统没有使用第三方扩展,其实现大致思路为:一个后台用户对于一个用户组,用户权限和后台栏目一一对应;

  • API接口主要使用模块做版本控制,使用RESTfull标准,权限及接口限制参考/api/models/User.php

  • 关于后台权限问题,后台权限是与Menu绑定的,在添加功能时先在后台【系统-菜单管理】中添加列表、增、删、改等菜单,然后到【用户-后台用户-权限管理】中【授权】,可以看到刚刚添加的菜单,勾选并提交后对应的用户组就有了该权限;

二、上传图片说明

1、上传单图和多图

  • 图片上传使用/common/widgets/images,需要扩展的可以自行修改,使用的是ajax将图片转化为base64编码后上传的;

  • 图片存储在storage/web/image目录下面。如果服务器解析到/web目录,则图片上传地址须修改,详情参考/web目录;

  • 图片上传配置文件在/common/config/paramsupload配置项中;

  • 后台图片上传使用的是backend/controllers/PbulicController控制器,上传成功后返回“201610/123456789123.jpg”。结合Yii::$app->params['upload']就可以生成图片路径。

  • 同时也可以使用\common\helpers\Html::src()方法生成图片路径。这个函数还可以生成类似“URL/index.php?path=201910/123456789123.jpg&w=100&h=100&fit=crop”的裁剪后的图片。其中URL可以是完整的路径,包含http,其配置在common/config/bootstarp.php的“@storageUrl”中配置。

2、编辑器使用UEditer(百度的编辑器)

  • 百度编辑器使用的是大裤衩的扩展,请自行查看;

  • 百度编辑器的上传路径配置在\common\comfig\params.phpueditorConfig配置项;

三、服务器配置

四、安装

一键安装方法如下:

1、下载源文件或git clone https://github.com/e282486518/yii2admin.git
2、composer install #安装依赖扩展
3、php ./yii install #配置环境、配置数据库并安装数据库
4、参照 doc 目录下的Nginx和Apache配置文件,配置服务器,并设置hosts文件。

超级管理员账号: admin 123456
普通管理员: guanli 123456
编辑人员: feifei 123456

五、常见错误

1、 [Composer\Repository\InvalidRepositoryException] 问题。 执行

composer self-update
composer global require "fxp/composer-asset-plugin"

2、bower-asset/jquery 等前端资源包无法找到的问题

composer global require "fxp/composer-asset-plugin"

并在composer.json文件中加入

    "repositories": [
        {
            "type": "composer",
            "url": "https://asset-packagist.org"
        }
    ]

六、预览

登录 首页 管理员 权限 配置 数据库 列表 编辑 配置皮肤 手机版 接口调用 前台

yii2admin's People

Contributors

aaronlei avatar e282486518 avatar pangxieke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yii2admin's Issues

请问有没有纯api接口的项目

本人一直写前端的,现在想自己做点小项目玩一下,请问有没有纯api接口的这种项目,主要编写业务逻辑代码的那种,谢谢~~~

百度编辑器的上传报错

百度编辑器在控制台报“后台配置项返回格式出错,上传功能将不能正常使用”
改成/web目录时也报这个错。
我正在尝试解决。
其它上传功能正常

下边配置感觉也啥错

'upload' => [
'url' => Yii::getAlias('@storageUrl/image/'),
//'path' => Yii::getAlias('@base/web/storage/image/'), // 服务器解析到/web/目录时,上传到这里
'path' => Yii::getAlias('@storage/web/image/'),
],

/* UEditor编辑器配置 */
'ueditorConfig' => [
    /* 图片上传配置 */
    'imageRoot'            => Yii::getAlias("@storage/web"), //图片path前缀
    //'imageRoot'            => Yii::getAlias("@base/web/storage"), //图片path前缀,服务器解析到/web/目录时,上传到这里
    'imageUrlPrefix'       => Yii::getAlias('@storageUrl'), //图片url前缀
    'imagePathFormat'      => '/image/{yyyy}{mm}/editor{time}{rand:6}',

    /* 文件上传配置 */
    'fileRoot'             => Yii::getAlias("@storage/web"), //文件path前缀
    //'fileRoot'             => Yii::getAlias("@base/web/storage"), //文件path前缀,服务器解析到/web/目录时,上传到这里
    'fileUrlPrefix'        => Yii::getAlias('@storageUrl'), //文件url前缀
    'filePathFormat'       => '/file/{yyyy}{mm}/editor{rand:4}_{filename}',

    /* 上传视频配置 */
    'videoRoot'            => Yii::getAlias("@storage/web"),
    //'videoRoot'            => Yii::getAlias("@base/web/storage"), // 服务器解析到/web/目录时,上传到这里
    "videoUrlPrefix"       => Yii::getAlias('@storageUrl'),
    'videoPathFormat'      => '/video/{yyyy}{mm}/editor{time}{rand:6}',

    /* 涂鸦图片上传配置项 */
    'scrawlRoot'           => Yii::getAlias("@storage/web"),
    //'scrawlRoot'           => Yii::getAlias("@base/web/storage"), // 服务器解析到/web/目录时,上传到这里
    "scrawlUrlPrefix"      => Yii::getAlias('@storageUrl'),
    'scrawlPathFormat'     => '/image/{yyyy}{mm}/editor{time}{rand:6}',
],

composer安装出错

使用 composer install 安装出错,下载不了 vendor 第三方扩展包

yii2admin\frontend\views\index\index.php 的问题

在我的安装版本里面,yii2admin没有安装在网站的根目录,所以有些问题就出现了。
比如首页顶部的轮播图片不显示,比如下部的文章列表前面的小图不出来。
看了一下代码,很明显是 views/index/index.php 里面,没有很好地使用 @web 别名,在用到图片的时候,直接使用了绝对路径。
比如顶部轮播的图片:
<img src="/static/images/assassins1.jpg" alt="第一张幻灯片"
实际上应该写成这样:
<img src="<?=Yii::getAlias('@web/static/images/assassins1.jpg')?>" alt="第一张幻灯片"

下面的正文前小图同样:
<img src="/static/images/01.jpg" />
应该写成
<img src="<?=Yii::getAlias('@web/static/images/01.jpg')?>" />

以上。

安装时报错,执行composer update 提示没有包

Your requirements could not be resolved to an installable set of packages.

Problem 1
- yiisoft/yii2 2.0.x-dev requires bower-asset/yii2-pjax ~2.0.1 -> no matching package found.
- yiisoft/yii2 dev-master requires bower-asset/yii2-pjax ~2.0.1 -> no matching package found.
- yiisoft/yii2 2.0.9 requires bower-asset/jquery 2.2.@stable | 2.1.@stable | 1.11.@stable | 1.12.@stable -> no matching package found.
- yiisoft/yii2 2.0.8 requires bower-asset/jquery 2.2.@stable | 2.1.@stable | 1.11.@stable -> no matching package found.
- yiisoft/yii2 2.0.7 requires bower-asset/jquery 2.2.
@stable | 2.1.@stable | 1.11.@stable -> no matching package found.
- yiisoft/yii2 2.0.6 requires bower-asset/jquery 2.1.@stable | 1.11.@stable -> no matching package found.
- yiisoft/yii2 2.0.10 requires bower-asset/jquery 2.2.@stable | 2.1.@stable | 1.11.@stable | 1.12.@stable -> no matching package found.
- Installation request for yiisoft/yii2 >=2.0.6 -> satisfiable by yiisoft/yii2[2.0.10, 2.0.6, 2.0.7, 2.0.8, 2.0.9, dev-master, 2.0.x-dev].

Potential causes:

Read https://getcomposer.org/doc/articles/troubleshooting.md for further common problems.

关于项目rule规则

对权限rbac中规则是在哪里写的呢?,或者说项目中用到规则了么?

安装后访问出现错误

作者您好,您的这套程序非常的不错,值得我去学习,但是在安装项目的过程中,遇到了如下问题,还请作者指明问题的所在!

具体的错误提示如下:
Warning: require(/Applications/XAMPP/xamppfiles/htdocs/yii2admin/vendor/composer/../symfony/polyfill-mbstring/bootstrap.php): failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/yii2admin/vendor/composer/autoload_real.php on line 66

Fatal error: require(): Failed opening required '/Applications/XAMPP/xamppfiles/htdocs/yii2admin/vendor/composer/../symfony/polyfill-mbstring/bootstrap.php' (include_path='.:/Applications/XAMPP/xamppfiles/lib/php') in /Applications/XAMPP/xamppfiles/htdocs/yii2admin/vendor/composer/autoload_real.php on line 66

环境配置如下:
1、项目文件yii2admin放置在/Applications/XAMPP/htdocs/文件夹下;
2、Apache配置:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/Applications/XAMPP/htdocs/yii2admin/frontend/web/"
ServerName www.yii2admin.com

Options FollowSymLinks
AllowOverride All
Order deny,allow
allow from all

ErrorLog "logs/www.yii2admin.com-error_log"
CustomLog "logs/www.yii2admin.com-access_log" common

<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/Applications/XAMPP/htdocs/yii2admin/backend/web/"
ServerName admin.yii2admin.com

Options FollowSymLinks
AllowOverride All
Order deny,allow
allow from all

ErrorLog "logs/admin.yii2admin.com-error_log"
CustomLog "logs/admin.yii2admin.com-access_log" common

<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/Applications/XAMPP/htdocs/yii2admin/storage/web/"
ServerName storage.yii2admin.com

Options FollowSymLinks
AllowOverride All
Order deny,allow
allow from all

ErrorLog "logs/storage.yii2admin.com-error_log"
CustomLog "logs/storage.yii2admin.com-access_log" common

3、hosts文件设置
#Yii2 sample application
127.0.0.1 www.yii2admin.com
127.0.0.1 admin.yii2admin.com
127.0.0.1 torage.yii2admin.com

麻烦作者您提醒问题出在哪里?应该如何去解决这个问题?谢谢!

apache配置问题

我按照你的单域名配置之后,启动 apache 过程中遇到了如下的问题

Expected but saw

#
   <VirtualHost *:80>
    ServerName www.yii2.cn
    RewriteEngine on
    DocumentRoot d:/php/demo/yii2admin
    
    # 应用前端主要重写规则
    RewriteCond %{HTTP_HOST} ^www.yii2.cn$ [NC] 
    RewriteCond %{REQUEST_URI} !^/(backend/web|admin|storage/web)
    RewriteRule !^/frontend/web /frontend/web%{REQUEST_URI} [L]

    # 重定向的网页没有一个斜线(注释,如果必要的话)
    #RewriteCond %{REQUEST_URI} ^/admin/$
    #RewriteRule ^(/admin)/ $1 [L,R=301]
    # 禁止斜线重定向
    RewriteCond %{REQUEST_URI} ^/admin$
    RewriteRule ^/admin /backend/web/index.php [L]
    # 后端应用程序的主要重写规则
    RewriteCond %{REQUEST_URI} ^/admin
    RewriteRule ^/admin(.*) /backend/web$1 [L]
    
    <Directory />
        Options FollowSymLinks
        AllowOverride None
        AddDefaultCharset utf-8
    </Directory>
    <Directory "d:/php/demo/yii2admin/frontend/web">
        RewriteEngine on
        # 如果一个目录或一个文件存在,请直接使用请求
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        # 否则去请求 index.php
        RewriteRule . index.php

        Require all granted
    </Directory>
    <Directory "d:/php/demo/yii2admin/backend/web">
        RewriteEngine on
        # 如果一个目录或一个文件存在,请直接使用请求
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        # 否则去请求 index.php
        RewriteRule . index.php

        Require all granted
    </Directory>
    <Directory "d:/php/demo/yii2admin/storage/web">
        RewriteEngine on
        # 如果一个目录或一个文件存在,请直接使用请求
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        # 否则去请求 index.php
        RewriteRule . index.php

        Require all granted
    </Directory>
   
    <filesMatch "\.(env|htaccess|htpasswd|svn|git)">
        Require all denied
    </filesMatch>
</VirtualHost>

样式和js为啥后台找不到

为啥前台有css和js,后台找不到,多了一层admin/
这个没找到在哪儿控制的
这个是前台的样式地址/assets/584fb616/global/plugins/ccslider/css/style.css
这个是后台的样式地址/admin/assets/584fb616/global/css/plugins-md.min.css
多了一层/admin/ 去掉就好了,这个是在哪里控制的?

SQL问题

image
\ /* 生成child树 *\/
$groups = static::find()->select(['group']) ->where(['pid'=>$item['id'], 'hide'=>0]) ->groupBy(['sort','group'])->orderBy('sortASC')->asArray()->column();`

nginx -- Yii2通用后台 二级目录配置

.env文件:

FRONTEND_URL = /yii2admin/frontend/web
BACKEND_URL = /yii2admin/backend/web
STORAGE_URL = /yii2admin/storage

nginx.conf文件:

# 前台重写
location /yii2admin/frontend/web/ {
	try_files $uri /yii2admin/frontend/web/index.php?$args;
}

# 后台重写
location /yii2admin/backend/web/ {
	try_files $uri /yii2admin/backend/web/index.php?$args;
}

(原doc/nginx.conf示例文件中没有这一部分,经测试,可用)

全站打包,安装后访问/admin报错

环境php-7.1.1 nginx-1.10
使用全站打包
./yii install 安装后访问 /admin,报错如下

An Error occurred while handling another error:
yii\base\InvalidRouteException: Unable to resolve the request "public/404". in /mnt/hgfs/yii/yii2admin/vendor/yiisoft/yii2/base/Module.php:537
Stack trace:
#0 /mnt/hgfs/yii/yii2admin/vendor/yiisoft/yii2/web/ErrorHandler.php(97): yii\base\Module->runAction('public/404')
#1 /mnt/hgfs/yii/yii2admin/vendor/yiisoft/yii2/base/ErrorHandler.php(111): yii\web\ErrorHandler->renderException(Object(yii\web\NotFoundHttpException))
#2 [internal function]: yii\base\ErrorHandler->handleException(Object(yii\web\NotFoundHttpException))
#3 {main}
Previous exception:
yii\base\InvalidRouteException: Unable to resolve the request "admin/login/login". in /mnt/hgfs/yii/yii2admin/vendor/yiisoft/yii2/base/Module.php:537
Stack trace:
#0 /mnt/hgfs/yii/yii2admin/vendor/yiisoft/yii2/web/Application.php(103): yii\base\Module->runAction('admin/login/log...', Array)
#1 /mnt/hgfs/yii/yii2admin/vendor/yiisoft/yii2/base/Application.php(386): yii\web\Application->handleRequest(Object(common\core\Request))
#2 /mnt/hgfs/yii/yii2admin/web/index.php(24): yii\base\Application->run()
#3 {main}

Next yii\web\NotFoundHttpException: 页面未找到。 in /mnt/hgfs/yii/yii2admin/vendor/yiisoft/yii2/web/Application.php:115
Stack trace:
#0 /mnt/hgfs/yii/yii2admin/vendor/yiisoft/yii2/base/Application.php(386): yii\web\Application->handleRequest(Object(common\core\Request))
#1 /mnt/hgfs/yii/yii2admin/web/index.php(24): yii\base\Application->run()
#2 {main}

新手,请问如何解决,谢谢

新建立应用主体怎么建立

建立和backend同级文件夹配置好之后报404错误
网上搜索有 还得配置 这个environments/index.php
但是这个项目中是没有这个文件的

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.