sanex/yii2-simple-filter
Composer 安装命令:
composer require sanex/yii2-simple-filter
包简介
Simple Yii2 filter module with checkboxes
README 文档
README
Yii2 Simple Filter Module
Yii2 Simple Filter Module v0.9.1dev #####Not compatible with older versions, because methods names were changed!
Video: http://www.youtube.com/watch?v=Vah2j5WzXIs
###Installation: How to install and configure modlue on clear Yii2 Base application (video): http://www.youtube.com/watch?v=Wnn_xVcTun0
Install module through composer
Run
$ php composer.phar require --prefer-dist sanex/yii2-simple-filter "dev-master"
or add
"sanex/yii2-simple-filter": "dev-master"
to the require section of composer.json file.
Last step: add 'enablePrettyUrl' => true to the urlManager in config file.
######Module not working with 'enablePrettyUrl' => false!
###How to use?
####Controller:
In controller, which has view (main view), where you want show data with filter, you must create object with instance of SimplyFilter module and set to him parameters:
use sanex\simplefilter\SimpleFilter;
...
$model = new Catalog;
$ajaxViewFile = '@sanex/catalog/views/catalog/catalog-ajax';
$filter = SimpleFilter::getInstance();
$filter->setParams([
'model' => $model,
'query' => $query,
'useAjax' => true,
'useCache' => true,
'useDataProvider' => true,
]);
$ajaxViewFile - alias (or path) to ajax view, where you want to show data. You must create that view file before continue.
setParams() properties:
model - model, which data need to filter;
query - (optional) - \yii\db\ActiveQuery object, see below;
useAjax - (optional, if not set - true) you can choose between Ajax or non-Ajax filtering by setting this parameter to boolean true or false values;
useCache - (optional, if not set - false) if (bool) true - return cached data, if (int) value - cache duration in seconds;
useDataProvider - (optional, if not set - false) if (bool) true - return data in Ajax View as dataProvider, if (bool) false or not set - return data as model;
As default, result query with filter looks like SELECT COUNT(*) FROM 'catalog' WHERE 'color' IN ('Green', 'Red')
If you want create custom query with filter you must set query parameter in setParams() method with \yii\db\ActiveQuery object as method parameter, that contain query parameters.
$query = new \yii\db\ActiveQuery($model);
$query->select(['id', 'name', 'size', 'price', 'country'])->where(['country' => 'Canada'])->orderBy(['price' => SORT_ASC]);
Method limit() of \yii\db\ActiveQuery object can set parameter 'pagination' => ['pageSize' => $this->limit], of ActiveDatapProvider object.
$query = new \yii\db\ActiveQuery($model);
$query->limit(25);
If limit() method not set, then limit for each query will set to default value - 50 rows per page.
If you want to use custom pagination with this filter, you can get offset from GET-paremeter page. Need to know, what for page values 0 and 1, offset value will 0, for all other values - will calculated by formula (page - 1) * limit.
In main view, you must call setFilter() method contain array with filter parameters.
######Note! property must be same as names of table columns which you want to filter, and values must be same as this columns data.
####Main View
$filter->setFilter([
[
'property' => 'color',
'caption' => 'Color',
'values' => [
'Red',
'Green',
'Blue',
'Black'
],
'class' => 'horizontal'
],
[
'property' => 'size',
'caption' => 'Size',
'values' => [
'45x45',
'50x50',
'60x60'
]
]
]);
You can set additional class or classes to each filters group by setting class property. This filter has two default style for checkbox: horizontal and vertical class for vertical checkboxes placement. If class property not set, used horizontal class as default.
You can set class value as string:
'class' => 'horizontal additional class'
or as array:
'class' => ['vertical', 'additionalClass']
Then, where you want to render ajax view with filtered data, call renderAjaxView() method:
$filter->renderAjaxView($ajaxViewFile, ['testParam' => $testParam]);
$ajaxViewFile - Ajax View file;
(array)$ajaxViewParams - (optional) parameters, that will be send to ajax view.
####Ajax View
In ajax view, you can get filtered data (model or dataProvider) through $simpleFilterData variable.
######Note! Module pass to ajax view only data! You must create in that ajax view <table></table> or use GridView widget to show data, same way as with all other Yii2 models!
sanex/yii2-simple-filter 适用场景与选型建议
sanex/yii2-simple-filter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 562 次下载、GitHub Stars 达 17, 最近一次更新时间为 2015 年 03 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「module」 「filter」 「yii」 「checkbox」 「yii2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sanex/yii2-simple-filter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sanex/yii2-simple-filter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sanex/yii2-simple-filter 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Nova searchable filter for belongsTo relationships.
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
Symfony DataGridBundle
Priveate for SkeekS CMS
Data provider for yii2
This Laravel Nova package allows you to detach filters from the filter dropdown
统计信息
- 总下载量: 562
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 17
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: WTFPL
- 更新时间: 2015-03-06