PHPackages                             yangsuda/slimcms - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. yangsuda/slimcms

ActiveProject[HTTP &amp; Networking](/categories/http)

yangsuda/slimcms
================

The SlimCMS framework

4.0.0(5mo ago)8611proprietaryJavaScriptPHP ^7.3 || ^8.0CI passing

Since Jul 1Pushed 3w ago3 watchersCompare

[ Source](https://github.com/yangsuda/slimcms)[ Packagist](https://packagist.org/packages/yangsuda/slimcms)[ Docs](http://github.com/yangsuda/slimcms)[ RSS](/packages/yangsuda-slimcms/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (7)Dependencies (2)Versions (12)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/3f442fb2e6ff49fb7876f29d6fb0233c5541b321658369472721cedf666e6cdc/687474703a2f2f706f7365722e707567782e6f72672f79616e67737564612f736c696d636d732f76)](https://packagist.org/packages/yangsuda/slimcms) [![Total Downloads](https://camo.githubusercontent.com/e6f8a49b8184a335d0441158acefe8e703eb23c9a42748609f638b02eff0fae5/687474703a2f2f706f7365722e707567782e6f72672f79616e67737564612f736c696d636d732f646f776e6c6f616473)](https://packagist.org/packages/yangsuda/slimcms) [![Latest Unstable Version](https://camo.githubusercontent.com/eb05433d21c7fe212d2bca2ca70b3d193cb7685d9c565681d1c6b8565921b937/687474703a2f2f706f7365722e707567782e6f72672f79616e67737564612f736c696d636d732f762f756e737461626c65)](https://packagist.org/packages/yangsuda/slimcms) [![PHP Version Require](https://camo.githubusercontent.com/930b416ffbceede45801f280bb007895430496cd8eddce19e8ea4f601b2a1655/687474703a2f2f706f7365722e707567782e6f72672f79616e67737564612f736c696d636d732f726571756972652f706870)](https://packagist.org/packages/yangsuda/slimcms)

### 预览

[](#预览)

列表添加编辑接口文档[![alt tag](https://camo.githubusercontent.com/470495df5c3fc00ac5bba8d8407466bbf6003c86b0010d2781ddec7afd14b010/68747470733a2f2f7777772e63733039302e636f6d2f75706c6f6164732f7573657275702f612f373030342f323032322f314134304641302d3936323932632e6a7067)](https://camo.githubusercontent.com/470495df5c3fc00ac5bba8d8407466bbf6003c86b0010d2781ddec7afd14b010/68747470733a2f2f7777772e63733039302e636f6d2f75706c6f6164732f7573657275702f612f373030342f323032322f314134304641302d3936323932632e6a7067)[![alt tag](https://camo.githubusercontent.com/9efb52d9a9976fe97aa683ce81e45536fdf2d5eb52cbd52dd95ec753f7b317db/68747470733a2f2f7777772e63733039302e636f6d2f75706c6f6164732f7573657275702f612f373030342f323032312f31363235413048332d5931333530382e706e67)](https://camo.githubusercontent.com/9efb52d9a9976fe97aa683ce81e45536fdf2d5eb52cbd52dd95ec753f7b317db/68747470733a2f2f7777772e63733039302e636f6d2f75706c6f6164732f7573657275702f612f373030342f323032312f31363235413048332d5931333530382e706e67)[![alt tag](https://camo.githubusercontent.com/6161b8f447bb823285afdc719d6ac08640f59a75b311bb9dacd32926cf4d6d07/68747470733a2f2f7777772e63733039302e636f6d2f75706c6f6164732f7573657275702f612f373030342f323032322f31413430464a342d31394349392e6a7067)](https://camo.githubusercontent.com/6161b8f447bb823285afdc719d6ac08640f59a75b311bb9dacd32926cf4d6d07/68747470733a2f2f7777772e63733039302e636f6d2f75706c6f6164732f7573657275702f612f373030342f323032322f31413430464a342d31394349392e6a7067)说明
==

[](#说明)

基于Slim4、PSR-7和PHP-DI容器实现。

生产环境下建议opcache扩展开启，本地测试性能会有近10倍的提升

数据库连接默认通过“mysql:host=XXX:XXX;”方式连接，有些情况下会连接不成功，可改成“mysql:host=XXX;port=XXX;”试试， 操作方式：将config/settings.php中的connecttype参数置为空

CORE\_DEBUG关闭情况下，系统配置默认会生成文件：/data/CompiledContainer.php，在部分情况下更新系统配置时，此文件不会更新，遇到此问题时，可将此文件直接删除，系统会重新再次生成，或将init.php中的$containerBuilder-&gt;enableCompilation(CSDATA);注释掉

开发版下载
-----

[](#开发版下载)

```
composer create-project yangsuda/slimcms [my-app-name] dev-master
```

将“\[my app name\]”替换为新应用程序所需的目录名。

建议将虚拟主机文档根目录指向新应用程序的“public/”目录。

安装配置
----

[](#安装配置)

通过运行“public/install/”进行安装

路由规则
----

[](#路由规则)

项目采用标准 REST 风格路由，路由配置文件位于 `app/routes/` 目录下：

- `app/routes/main.php` - 前台路由
- `app/routes/admin.php` - 后台路由
- `app/routes/plugin/` - 插件路由（可选）

### 路由注册方式

[](#路由注册方式)

使用 `App\Core\RouteAction` 提供类似 ThinkPHP/Laravel 风格的路由注册：

```
use App\Core\RouteAction as Route;

Route::get('/path', 'Controller@method');    // GET
Route::post('/path', 'Controller@method');   // POST
Route::gp('/path', 'Controller@method');     // GET + POST
Route::any('/path', 'Controller@method');    // 所有方法

// 路由分组，支持链式挂载中间件
Route::group('/admin', function () {
    Route::get('/index', 'admin\MainController@index');
    Route::gp('/login', 'admin\LoginController@login');
    Route::group('', function () {
        Route::gp('/{path1}/{path2}'); // 动态路由参数
    })->add(AdminAuthMiddleware::class);
})->add(SessionMiddleware::class);
```

### 控制器规范

[](#控制器规范)

控制器位于 `app/Controller/` 目录下，按模块分子目录：

- `app/Controller/main/` - 前台控制器
- `app/Controller/admin/` - 后台控制器
- `app/Controller/plugin/` - 插件控制器

控制器类名以 `Controller` 结尾，如 `MainController`、`LoginController`。路由中使用 `模块\类名Controller@方法名` 格式指定，框架会自动补全完整类名 `App\Controller\`。

### 路由示例

[](#路由示例)

前台路由（`app/routes/main.php`）：

```
Route::get('/', 'main\MainController@index');
Route::get('/captcha', 'main\MainController@captcha');
```

后台路由（`app/routes/admin.php`）：

```
Route::group('/admin', function () {
    Route::gp('/login', 'admin\LoginController@login');
    Route::get('/logout', 'admin\LoginController@logout');

    Route::group('', function () {
        Route::get('/index', 'admin\MainController@index');
        Route::gp('/updatePwd', 'admin\MainController@updatePwd');
        Route::gp('/{path1}/{path2}');
    })->add(AdminAuthMiddleware::class);
})->add(SessionMiddleware::class);
```

数据获取
----

[](#数据获取)

通过self::input()获取外部传参

或

self::inputInt获取强转为int类型的外部传参

self::inputFloat获取强转为float类型的外部传参

self::inputString获取强转为string类型的外部传参

数据结构
----

[](#数据结构)

Model层数据统一以Output对象形式返回，

通过getCode方法获取状态码，200为正确，其它为错误，如：$output-&gt;getCode()

通过withCode方法设置状态码，如：$output-&gt;withCode(24024)

通过getData方法获取返回值，如：$output-&gt;getData()

通过withData方法设置返回值，如：$output-&gt;withData(\['value'=&gt;'test'\])

通过getTemplate方法获取模板，如：$output-&gt;getTemplate()

通过withTemplate方法设置设置解析的模板，如：$output-&gt;withTemplate('/index')

通过getReferer方法获取来路URL，如：$output-&gt;getReferer()

通过withReferer方法设置来路URL，如：$output-&gt;withReferer('/test')

数据输出
----

[](#数据输出)

共有5种输出方式

1、$this-&gt;view(),用于模板渲染加载输出

2、$this-&gt;directTo(),直接跳转，提示信息存储在cookie中，如需显示，在模板中通过$data\[errorCode\]、$data\[errorMsg\]加载

3、$this-&gt;json(),返回json数据

4、self::response(),根据请求的content-type返回相应的数据类型

功能插件
----

[](#功能插件)

框架本身只提供基础构建，一些具体功能通过插件化实现，目前有接口插件、支付插件、文件管理插件、文件安全校验插件四个插件，后期会根据实际需要增加更多插件。

通过在插件市场下载安装，对于已经下载的插件可开启或关闭，卸载插件时会提示是否删除安装时添加的相应表，如果不删除相应表，再次安装时将会提示安装失败

数据接口
----

[](#数据接口)

需要先安装接口插件，接口文档和数据接口通过后台表单开放接口权限控制，分“列表、展示、添加修改、删除、导出、表单结构、审核、统计”8种权限， 如不能满足需求，可自定义接口。

数据统一以json格式返回，状态码200为正常，其它为错误

```
{
      "code": 200,
      "data": {},
      "msg": 操作成功
}
```

默认增删改查定制化
---------

[](#默认增删改查定制化)

可通过在/app/Table文件夹中创建对应表的类文件来实现数据输入输出的定制化，格式为“表名Table.php”，（注：第一个字母要大写），如admin表，在文件夹中创建AdminTable.php文件

数据列表（forms/dataList）

可在上面的类文件中定义 dataListInit、dataListBefore、dataListAfter 方法来实现列表的前、中、后三个阶段的数据输入输出控制，（注：状态码返回200为成功，其它为报错），具体参见Forms.php文件，如：

```
public function dataListBefore(&$param): int
{
    return 200;
}
```

数据保存（forms/dataSave）

可在上面的类文件中定义 dataSaveInit、dataSaveBefore、dataSaveAfter 方法来实现数据保存的前、中、后三个阶段的数据输入输出控制，（注：状态码返回200为成功，其它为报错），具体参见Forms.php文件，如：

```
public function dataSaveBefore(&$data, $row = [], $options = []): int
{
    return 200;
}
```

数据详细（forms/dataView）

可在上面的类文件中定义 dataViewBefore、dataViewAfter 方法来实现数据详细的前、后两个阶段的数据输入输出控制，（注：状态码返回200为成功，其它为报错），具体参见Forms.php文件，如：

```
public function dataViewAfter(&$data): int
{
    return 200;
}
```

数据删除（forms/dataDel）

可在上面的类文件中定义 dataDelBefore、dataDelAfter 方法来实现数据删除的前、后两个阶段的数据输入输出控制，（注：状态码返回200为成功，其它为报错），具体参见Forms.php文件，如：

```
public function dataDelBefore($data, $options = []): int
{
    return 200;
}
```

数据审核（forms/dataCheck）

可在上面的类文件中定义 dataCheckBefore、dataCheckAfter 方法来实现数据审核的前、后两个阶段的数据输入输出控制，（注：状态码返回200为成功，其它为报错），具体参见Forms.php文件，如：

```
public function dataCheckBefore($ids, $ischeck, $options): int
{
    return 200;
}
```

数据统计（forms/dataCount）

可在上面的类文件中定义 dataCountBefore 方法来实现数据统计的前的数据输入控制，（注：状态码返回200为成功，其它为报错），具体参见Forms.php文件，如：

```
public function dataCountBefore($param)
{
    return 200;
}
```

生成的表单HTML（forms/dataFormHtml）

可在上面的类文件中定义 getFormHtmlBefore、getFormHtmlAfter 方法来实现生成的表单HTML的前、后两个阶段的数据输入输出控制，（注：状态码返回200为成功，其它为报错），具体参见Forms.php文件，如：

```
public function getFormHtmlBefore($fields, $row, $form, $options)
{
    return 200;
}
```

数据导出（forms/dataExport）

可在上面的类文件中定义 dataExportBefore、dataExportAfter 方法来实现数据导出的前、后两个阶段的数据输入输出控制，（注：状态码返回200为成功，其它为报错），具体参见Forms.php文件，如：

```
public function dataExportBefore($condition, $result)
{
    return 200;
}
```

模板标签
----

[](#模板标签)

模板中可直接加载变量 $code(状态码)、$msg(提示信息)、$referer(来路URL)、$data(数据)、$cfg(系统配置参数)

如加载数组中某一元素，模板中可通过$data\[xxx\]\[xxx\]...加载。

注：在某些情况下，会导致变量加载失败，如在汉字或字母中间加载某一变量，变量需用{}括起来，如：{$data\[xxx\]\[xxx\]}

条件判断标签

```
{if ...}
...
{elseif ...}
...
{else}
....
{/if}
```

或

```

...

...

....

```

遍历循环标签

```
{loop $XXX $k $v}
$v[...]
...
{/loop}
```

或

```

$v[...]
...

```

注：$k也可以不写，写成{loop $XXX $v}

表单列表数据标签

```
{list fid=表单ID}
$v[...]
...
{/list}
```

更多标签说明具体参见Template.php

附件上传
----

[](#附件上传)

默认是上传附件本地存储， 如想改成阿里云的OSS存储

1、加载阿里云的SDK

```
composer require aliyuncs/oss-sdk-php
```

2、修改调用参数$accessKeyId、$accessKeySecret等：app/Model/aliyun/AliOss.php

3、修改加载的上传类：app/Core/settings.php

将new Upload()改成new AliOss(),注意相应的引用要改一下

数据库分表
-----

[](#数据库分表)

对于像日志类的表如果长时间积累可能会导致表数据非常庞大，影响执行效率，所以可以考虑分表操作。

具体操作：

在app/Table/文件夹中创建相应表的类文件，文件名称格式：表名+'Table.php'(表名第一个字母大写)，如:AdminlogTable.php

在构造函数中增加$this-&gt;subtable($tableName, $extendName);

如：

```
public function __construct(Request $request, string $tableName, string $extendName = null)
{
        //根据年份进行分表
        if (!isset($extendName)) {
            $extendName = date('Y');
            $this->subtable($tableName, $extendName);
        }
        parent::__construct($request, $tableName, $extendName);
}
```

以示例为例

数据库中将自动创建表adminlog2022

数据调用方式:self::t('adminlog')-&gt;...（默认调用当前年份数据），如需调用2021数据，:self::t('adminlog','2021')-&gt;...

###  Health Score

46

—

FairBetter than 92% of packages

Maintenance85

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~184 days

Recently: every ~56 days

Total

11

Last Release

27d ago

Major Versions

2.2.1 → 3.0.02023-03-16

3.0.5.x-dev → 4.0.02026-03-20

4.0.1.x-dev → 5.0.0.x-dev2026-07-22

PHP version history (3 changes)2.0.0PHP ^7.3

3.0.1PHP ^7.3 || ^8.0

5.0.0.x-devPHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/298224a56f4a7fd56245f3d10e499f69311f432cfb85ef7e67418bfcc7fa1c9f?d=identicon)[zhucy](/maintainers/zhucy)

---

Top Contributors

[![yangsuda](https://avatars.githubusercontent.com/u/20188527?v=4)](https://github.com/yangsuda "yangsuda (677 commits)")

---

Tags

restrouterpsr7slimCMS

### Embed Badge

![Health badge](/badges/yangsuda-slimcms/health.svg)

```
[![Health](https://phpackages.com/badges/yangsuda-slimcms/health.svg)](https://phpackages.com/packages/yangsuda-slimcms)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
