1 Star 0 Fork 34

xzone / lightCMS

forked from Eddy / lightCMS 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

LightCMS

Scrutinizer Code Quality StyleCI Build Status PHP Version

项目简介

lightCMS是一个轻量级的CMS系统,也可以作为一个通用的后台管理框架使用。lightCMS集成了用户管理、权限管理、日志管理、菜单管理等后台管理框架的通用功能,同时也提供模型管理、分类管理等CMS系统中常用的功能。lightCMS代码一键生成功能可以快速对特定模型生成增删改查代码,极大提高开发效率。

lightCMS基于Laravel 5.5开发,前端框架基于layui

LightCMS&Laravel学习交流QQ群:972796921

注意:如果想使用基于最新Laravel 6.0(6.x)的版本,可使用laravel-6.x分支。

功能点一览

后台:

  • 基于RBAC的权限管理
  • 管理员、日志、菜单管理
  • 分类管理
  • 配置管理
  • 模型、模型字段、模型内容管理(后台可自定义业务模型,方便垂直行业快速开发)
  • 会员管理
  • 评论管理
  • 基于Tire算法的敏感词过滤系统
  • 普通模型增删改查代码一键生成

前台:

  • 用户注册登录(包括微信、QQ、微博三方登录)
  • 模型内容详情页、列表页
  • 评论相关

更多功能待你发现~

后台预览

首页

系统管理

系统环境

linux/windows & nginx/apache/iis & mysql 5.5+ & php 7.0+

  • PHP >= 7.0.0
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Mbstring PHP Extension
  • Tokenizer PHP Extension
  • XML PHP Extension

注意事项

  • 如果缓存、队列、session用的是 redis 驱动,那还需要安装 redis 和 php redis 扩展
  • 如果PHP安装了opcache扩展,请启用opcache.save_commentsopcache.load_comments配置(默认是启用的),否则无法正常使用菜单自动获取功能

系统部署

获取代码并安装依赖

首先请确保系统已安装好composer。国内用户建议先设置 composer 镜像,避免安装过程缓慢。

cd /data/www
git clone git_repository_url
cd lightCMS
composer install

系统配置并初始化

设置目录权限:storage/bootstrap/cache/目录需要写入权限。

# 此处权限设置为777只是为了演示操作方便,实际只需要给web服务器写入权限即可
sudo chmod 777 -R storage/ bootstrap/cache/

新建一份环境配置,并配置好数据库等相关配置:

cp .env.example .env

初始化系统:

php artisan migrate --seed

配置Web服务器(此处以Nginx为例)

server {
    listen 80;
    server_name light.com;
    root /data/www/lightCMS/public;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        #不同配置对应不同的环境配置文件。比如此处应用会加载.env.pro文件,默认不配置会加载.env文件。此处可根据项目需要自行配制。
        #fastcgi_param   APP_ENV pro;
        include fastcgi_params;
    }
}

后台登陆

后台访问地址:/admin/login

默认用户(此用户为超级用户,不受权限管理限制):admin/admin

权限管理

基于角色的权限管理。只需新建好角色,给对应的角色分配好相应的权限,最后给用户指定角色即可。lightCMS中权限的概念其实就是菜单,一条菜单对应一个laravel的路由,也就是一个具体的操作。

菜单自动获取

只需要按约定方式写好指定路由的控制器注释,则可在菜单管理页面自动添加/更新对应的菜单信息。例如:

/**
 * 角色管理-角色列表
 *
 * 取方法的第一行注释作为菜单的名称、分组名。注释格式:分组名称-菜单名称。
 * 未写分组名称,则直接作为菜单名称,分组名为空。
 * 未写注释则选用uri作为菜单名,分组名为空。
 */
public function index()
{
    $this->breadcrumb[] = ['title' => '角色列表', 'url' => ''];
    return view('admin.role.index', ['breadcrumb' => $this->breadcrumb]);
}

需要注意的是,程序可以自动获取菜单,但是菜单的层级关系还是需要在后台手动配置的。

配置管理

首先需要将config/light.php配置文件中的light_config设置为true

然后只需在配置管理页面新增配置项或编辑已存在配置项,则在应用中可以直接使用laravel的配置获取函数config获取指定配置,例如:

// 获取 key 为 SITE_NAME 的配置项值
$siteName = config('light_config.SITE_NAME');

标签管理

模型内容打标签是站点的一项常用功能,lightCMS内置了打标签功能。添加模型字段时选择表单类型为标签输入框即可。

lightCMS采用中间表(content_tags)来实现标签和模型内容的多对多关联关系。

模型管理

lightCMS支持在后台直接创建模型,并可对模型的表字段进行自定义设置。设置完模型字段后,就不需要做其它工作了,模型的增删改查功能系统已经内置。

这里说明下模型的表单验证及后端的保存和更新处理。如果有自定义表单验证需求,只需在app/Http/Request/Admin/Entity目录下创建模型的表单请求验证类即可。类名的命名规则:模型名+Request。例如User模型对应的表单请求验证类为UserRequest

如果想自定义模型的新增/编辑前端模板,只需在app/resources/views/admin/content目录下创建模板文件即可。模板文件的命名需遵循如下命名规则:模型名_add.blade.php。例如User模型对应的模板文件名为user_add.blade.php

如果想自定义模型的保存和更新处理逻辑,只需在app/Http/Controllers/Admin/Entity目录下创建模型的控制器类即可,saveupdate方法实现可参考app/Http/Controllers/Admin/ContentController。类名的命名规则:模型名+Controller。例如User模型对应的控制器类为UserController。同理,如果想自定义列表页,按上述规则定义indexlist方法即可。

系统日志

lightCMS集成了一套简单的日志系统,默认情况下记录后台的所有操作相关信息,具体实现可以参考Log中间件。

可以利用Laravel任务调度来自动清理系统日志。启用任务调度需要在系统的计划任务中添加如下内容:

* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

可以通过配置log_async_write项来决定是否启用异步写入日志(默认未启用),异步写入日志需要运行Laravel队列处理器

php artisan queue:work

代码一键生成

对于一个普通的模型,管理后台通常有增删改查相关的业务需求。lightCMS拥有一键生成相关代码的能力,在建好模型的数据库表结构后,可以使用如下artisan命令生成相关代码:

# config 为模型名称 配置 为模型中文名称
php artisan light:basic config 配置

成功执行完成后,会创建如下文件(注意:相关目录需要有写入权限):

  • routes/auto/config.php 路由:包含模型增删改查相关路由,应用会自动加载routes/auto/目录下的路由。
  • app/Model/Admin/Config.php 模型:$searchField 属性用来配置搜索字段,$listField 用来配置列表视图中需要展示哪些字段数据。
  • app/Repository/Admin/ConfigRepository.php 模型服务层:默认有一个list方法,该方法用来返回列表数据。需要注意的是如果列表中的数据不能和数据库字段数据直接对应,则可对数据库字段数据做相应转换,可参考list方法中的transform部分。
  • app/Http/Controllers/Admin/ConfigController.php 控制器:默认有一个$formNames属性,用来配置新增/编辑表单请求字段的白名单。此属性必需配置,否则获取不到表单数据。参考 request 对象的 only 方法
  • app/Http/Requests/Admin/ConfigRequest.php 表单请求类:可在此类中编写表单验证规则,参考 Form Request Validation
  • resources/views/admin/config/index.blade.php 列表视图:列表数据、搜索表单。
  • resources/views/admin/config/index.blade.php 新增/编辑视图:只列出了基本架构,需要自定义相关字段的表单展示。参考 layui form

最后,如果想让生成的路由展示在菜单中,只需在菜单管理页面点击自动更新菜单即可。

搜索字段($searchField)配置说明

通过配置搜索字段,可以很方便的在模型的列表页展示搜索项。如下是一个示例配置:

    public static $searchField = [
        'name' => '用户名', // input搜索类型。key 为字段名称,value 为标题
        'status' => [ // key 为字段名称,value 为相关配置
            'showType' => 'select', // 下拉框选择搜索类型
            'searchType' => '=', // 说明字段在数据库的搜索匹配方式,默认为like查询
            'title' => '状态', // 标题
            'enums' => [ // select下拉搜索项
                0 => '禁用',
                1 => '启用',
            ],
        ],
        'created_at' => [ // key 为字段名称,value 为相关配置
            'showType' => 'datetime', // 日期时间搜索类型
            'title' => '创建时间' // 标题
        ]
    ];

列表字段($listField)配置说明

通过配置列表字段,可以很方便的在模型的列表页展示列表项。如下是一个示例配置:

    public static $listField = [
        // pid 是列表字段名(不一定是模型数据库表的字段名,只要列表数据接口返回数据包含该字段即可);title、width、sort 等属性参考 layui 的 table 组件表头参数配置即可
        'pid' => ['title' => '父ID', 'width' => 80],
        'entityName' => ['title' => '模型', 'width' => 100], 
        'userName' => ['title' => '用户名', 'width' => 100],
        'content' => ['title' => '内容', 'width' => 400],
        'reply_count' => ['title' => '回复数', 'width' => 80, 'sort' => true],
        'like' => ['title' => '喜欢', 'width' => 80, 'sort' => true],
        'dislike' => ['title' => '不喜欢', 'width' => 80, 'sort' => true],
    ];

敏感词检测

如果需要对发表的内容(文章、评论等)进行内容审查,则可直接调用LightCMS提供的checkSensitiveWords函数即可。示例如下:

$result = checkSensitiveWords('出售正品枪支');
print_r($result);
/*
[
    "售 出售 枪",
    "正品枪支"
]
*/

图片上传

LightCMS中图片默认上传到本地服务器。如果有自定义需求,比如上传到三方云服务器,可参考config/light.php配置文件中的image_upload配置项说明,自定义处理类需要实现App\Contracts\ImageUpload接口,方法的返回值数据结构和系统原方法保持一致即可。

{
    "code": 200,
    "state": "SUCCESS",
    "msg": "",
    "url": "xxx"
}

系统核心函数、方法说明

做这个说明的主要目的是让开发者了解一些核心功能,方便自定义各类功能开发。毕竟框架是不可能代劳所有事情滴^_

方法名称:App\Repository\Admin\CategoryRepository::tree()

功能说明:

返回分类的树结构信息。数据结构可以参考下图所示:

tree

此数据结构基本包含了分类的所有结构化信息。相关字段的含义也比较清楚,此处只对path字段做下说明:该字段是指当前分类的所有上级分类链,这样可以很方便的知道某个分类的所有父级分类。比如图中的test分类的path字段值为[1, 2],那么很容易的知道它的父级分类是:游戏 射击

前台相关

用户注册登录

LightCMS集成了一套简单的用户注册登录系统,支持微信、QQ、微博三方登录。三方登录相关配置请参考config/light.php

TODO

  • 模版管理+模版标签

完善中。。。

说明

有问题可以提 issue ,为项目贡献代码可以提 pull request

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [2019] [cumtsjh@163.com] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

lightCMS是一个轻量级的CMS系统,也可以作为一个通用的后台管理框架使用。 展开 收起
PHP
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
PHP
1
https://gitee.com/fuwenbin/lightCMS.git
git@gitee.com:fuwenbin/lightCMS.git
fuwenbin
lightCMS
lightCMS
master

搜索帮助