PHPackages                             yanlongli/yii2-fast - 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. [Caching](/categories/caching)
4. /
5. yanlongli/yii2-fast

AbandonedYii2-extension[Caching](/categories/caching)

yanlongli/yii2-fast
===================

Yii2 快速开发转换，参考ThinkPHP、Laravel框架进行基础功能的扩展，如Request、Cache、Db、Session、Cookie等

0.0.5.18(5y ago)190MITPHPPHP &gt;=5.6.0

Since Aug 2Pushed 5y ago1 watchersCompare

[ Source](https://github.com/Yanlong-LI/yii2-fast)[ Packagist](https://packagist.org/packages/yanlongli/yii2-fast)[ Docs](http://blog.yanlongli.com/)[ RSS](/packages/yanlongli-yii2-fast/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (1)Versions (34)Used By (0)

Yii2 快速开发扩展插件
=============

[](#yii2-快速开发扩展插件)

> 支持Config、Lang、Request、AR(db/model)、Cache、Pagination、Controller

前言
--

[](#前言)

本扩展包是作者长期使用 `ThinkPHP` 和 `Laravel` 框架之下,养成的一些习惯。奈何Yii2框架不支持，于是工作过程中开发并一点点完善此扩展。

介绍
--

[](#介绍)

仿照 `ThinkPHP` 和 `Laravel` 框架编写此扩展，所以很多代码可能会直接由这两个框架中的代码直接复制过来，也有直接仿照源代码进行细微调整以适应Yii2框架。如果有问题欢迎来`Gitee`提交问题。 同时在项目内也会附带上两个框架的开源许可协议。

计划支持
----

[](#计划支持)

```
Request、Cookie、Session、Cache、Db

以及支持表模型的多态关联、自动化的远程关联

```

使用方法
----

[](#使用方法)

### Request

[](#request)

#### 变量获取

[](#变量获取)

变量获取使用 Request 类的如下方法及参数：

变量类型方法('变量名/变量修饰符','默认值') 变量类型方法包括：

方法描述备注get获取 $\_GET 变量post获取 $\_POST 变量支持JSON、XMLparam参数集合支持获取get和post的集合，以Post为主合并数组except参数过滤该方法第一个参数可过滤指定的参数，兼容字符串（用英文逗号分隔）、数组only指定参数该方法用于获取列表内的输入参数，与filter相反### Config

[](#config)

方法描述备注get获取配置支持递归获取`(site.name)`set设置配置支持递归`('site.name','app')`### Controller

[](#controller)

```
assign 设置视图参数 支持数组批量设置
render 和Yii作用一样，无需传递视图名称，默认为当前方法名称

```

### Cache

[](#cache)

```
get 获取
set 设置
delete 删除
has 判断是否存在
pull 获取并删除
inc 自增 支持步长
dec 自减 支持步长
clear 清空所有缓存

```

### ActiveRecord

[](#activerecord)

```
morphOne 多态一对一关联
morphMany 多态一对多关联
morphTo 多态反向关联
getMorphAliasName 多态类获取别名
hasOneThrough 远程一对一关联
hasManyThrough 远程一对多关联
hasOne 一对一关联
hasMany 一对多关联
belongsTo 反向关联

```

### Pagination

[](#pagination)

```
page($model,$param) 设定好条件的模型，参数 [pageConfig=>[page,totalCount...]] 设置分页类的参数

```

### Lang

[](#lang)

```
自动识别当前浏览器的语言 目前支持中文地区和英文地区
t() 作用同 Yii::t()
getLang() 获取当前语言
setLang 设置语言
langAliases 根据别名获取语言
init 初始化语言分类 默认为 app

```

### Cookie

[](#cookie)

```
set 设置
get 获取
deltete 删除
clear 清空
has 判断是否存在

```

### Validator

[](#validator)

[验证器请参考ThinkPHP](https://www.kancloud.cn/manual/thinkphp6_0/1037623)部分功能未实现

### Schedule

[](#schedule)

```
【参考】 Laravel 仅实现主要功能

没有 before 和 after 、onSuccess 、 onFailure
这玩意你自己写的任务自己不知道啥时候执行还是结束？是成功还是失败？

继承 yanlongli\yii2\fast\Schedule
并实现 public function schedule();

$this->call() 闭包函数，内部调用 call_user_func，支持携带参数
$this->command(string) 调用 Yii 执行命令
$this->exec(string) 调用 php exec 具有一定风险的功能，使用前请确保该函数已开启
$this->task(Task) 可执行继承自 yanlongli\yii2\fast\lib\schedule\Task 的任务，实现 run 方法，可重写 handleSuccess(run返回)、handleError(Exception)

```

`ps:具体支不支持请关注更新日志和操作说明`

已支持
---

[](#已支持)

类名用途备注Request获取请求参数支持json、xml内容类型Config获取配置参数支持Param及新增文件，排除main、test等文件Pagination模型分页查询需要传递ActiveRecord模型Lang语言快速渲染基于Yii原有国际化语言支持Cache缓存读写、自增减基于原始Yii文件缓存系统的缓存类Controller控制器扩展，视图渲染，参数绑定render、assignActiveRecord数据库模型多态关联、远程关联等总结
--

[](#总结)

原框架设计接口包括兼容性和逻辑性一定是比次扩展好用，但是呢，Yii2框架本身也有一些封装，所以够用就行。

因为我比较懒

更新日志
----

[](#更新日志)

```
2020年9月27日
修复初始化依赖时自动设置了不允许的语言，后续需要手动恢复语言并重新初始化的问题
2020年9月3日
增加 初始化 Lang 扩展时可设置允许的语言集合，防止自动获取语言时获取到异常的数据

2020年8月19日
调整 支持 多对多时 toArray() 调用
2020年8月19日
增加 ActiveRecord 调用 toArray() 时返回 with() 关联的数据

2020年8月13日
修复 require 配置文件时，配置文件内的变量作用域溢出冲突问题

2020年7月29日
新增任务调度功能
支持定时任务
支持频率调度任务，最低为 1分钟/次,最长支持年为单位

2019年11月14日
改进Config 支持层级递归读取key中携带“.”的配置获取
如：
    a.php
    return [
        'b.c.d'=>[
            'e'=>1
            ]
    ];

    可以直接使用
    Config::get('a.b.c.d.e'); //获取e的值

2019年10月23日
改进Config 支持不规范配置 key 中携带 “.” 的配置获取

2019年10月16日
修复Config获取子参数默认值不生效问题

2019年9月29日
修复Request中获取子参数需求传递array问题，不需要严格模式

2019年9月24日
修复多态关联别名为数字时，数组合并会重置索引导致返回非预期模型问题

2019年9月23日
改进验证器在规则为数组时返回规则提示信息不会替换变量(:attribute,:rule)问题
增加Request检测是否存在指定请求参数

2019年8月31日
修复获取POST+GET参数时返回Null导致非数组不能合并报错问题

2019年8月21日
修复Request在接收Json或XML格式数据时数据格式不正确导致报错问题，返回空数组或默认值

2019年8月14日
紧急修复，Lang 初始化 调用 \Yii::$app->request 在命令行模式 yii\base\Request 类非 yii\web\Request 问题导致报错问题
Config 新增支持递归参数合并
Request 新增Method判断，参考 ThinkPHP
新增 Cookie操作，源码来自 ThinkPHP
Config 新增支持子目录配置文件，合并到同名主目录配置文件（如果存在）
调整 Request 参数修饰符，支持多字符类型 来源 ThinkPHP
新增 Validator 验证器 来源 ThinkPHP

2019年8月13日
修复 Config 连贯模式不存在的主参数导致报错问题

2019年8月10日
紧急修复语言包别名加载错误问题
2019年8月9日
Config 修复主配置比-local.php级别高的问题

2019年8月8日
Config 排除非php文件

2019年8月5日
更换包名
yanlongli/yii2-fast
安装旧包的可能需要移除后重新安装
命名空间不变

2019年8月5日
修复Config 未初始化时 params未放置到数组中
增加自动初始化类
开放加载自定义配置文件

2019年8月5日
增加Config类
    目前仅支持读取 get
    排除Yii的主要配置如 main test bootstrap codeception
    所有配置根据文件命名储存在数组中
        如 a.php
            [
                'password'=>123456
            ]
        使用 Config::get('a.password');// 读取password，
        使用 Config::get('a'); //读取该配置文件的所有内容
    与common/config合并（如果存在）
page 更名 Pagination
Request 更新支持获取 application/json 格式和application/xml格式

2019年8月3日
修复Request::param()获取所有请求参数时未返回内容问题
优化Request 针对Boolean类型的识别判断
新增 page 数据快速分页类

2019年8月2日
初始化项目
增加Request
增加模型的一对一、一对多、相对关联、远程一对一、远程一对多、多态关联、多态相对关联
增加Cache
增加Lang

```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 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 ~18 days

Recently: every ~46 days

Total

32

Last Release

1906d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bceb058b66ce0ec7be2d841d6fedb72ad0ab12abbd76ff5382b66599161542d8?d=identicon)[yanlong-li](/maintainers/yanlong-li)

---

Top Contributors

[![yanlong-li](https://avatars.githubusercontent.com/u/20129263?v=4)](https://github.com/yanlong-li "yanlong-li (31 commits)")

---

Tags

requestlaravelrediscachescheduledbsessionfastcookieyiithinkphp

### Embed Badge

![Health badge](/badges/yanlongli-yii2-fast/health.svg)

```
[![Health](https://phpackages.com/badges/yanlongli-yii2-fast/health.svg)](https://phpackages.com/packages/yanlongli-yii2-fast)
```

###  Alternatives

[awssat/laravel-visits

Laravel Redis visits counter for Eloquent models

975163.6k2](/packages/awssat-laravel-visits)[karriere/state

Laravel package for storing current application state in cache/session

1718.5k](/packages/karriere-state)

PHPackages © 2026

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