matrozov/yii2-pro-active-query
Composer 安装命令:
composer require matrozov/yii2-pro-active-query
包简介
Dynamically extensible ActiveQuery class
README 文档
README
This extension provides dynamical customization ActiveQuery filters.
For license information check the LICENSE-file.
Install
Either run
$ php composer.phar require matrozov/yii2-pro-active-query
or add
"matrozov/yii2-pro-active-query": "@dev"
to the require section of your composer.json file.
Usage
Simply add ProActiveQueryTrait trait to your ActiveRecord class and specify ProActiveQuery query-function like this:
class MyClass extends ActiveRecord { use ProActiveQueryTrait; ... public static function queryMyFunc(ActiveQuery &$query) { $query->andWhere(['deleted_at' => null']); } }
Now, you can simple selection from database with your filter function:
$items = MyClass::find()->myFunc()->all();
Any function with any parameters with query-prefix can be called from ActiveQuery:
public static function queryStatusIs(ActiveQuery &$query, $status) { $query->andWhere(['status' => $status]); }
$items = MyClass::find()->statusIs('ready')->all();
You can use additional trait for share query-function between ActiveRecord classes.
统计信息
- 总下载量: 951
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-08-01