simtecsystem/cakephp-filter
Composer 安装命令:
composer require simtecsystem/cakephp-filter
包简介
Filter plugin for CakePHP >3.6
README 文档
README
Installation
You can install this plugin into your CakePHP application using composer.
The recommended way to install composer packages is:
composer require simtecsystem/cakephp-filter
Load the plugin
Add following to your config/bootstrap.php
Plugin::load('BRFilter');
Usage
Controller class
public function index() { $this->loadComponent('BRFilter.Filter'); // add filter and options $this->Filter->addFilter([ 'filter_id' => ['field' => 'Posts.id', 'operator'=>'='], 'filter_title' => ['field' => 'Posts.title', 'operator' => 'LIKE', 'explode' => 'true'], 'filter_category_id' => ['field'=> 'Posts.category_id', 'operator' => 'IN' ] ]); // get conditions $conditions = $this->Filter->getConditions(['session'=>'filter']); // set url for pagination $this->set('url', $this->Filter->getUrl()); // apply conditions to pagination $this->paginate['conditions'] = $conditions; // get pagination $this->set('posts', $this->paginate($this->Posts)); // ... }
Template views
You have to add a form to your index.ctp, corresponding with the alias of your filter configuration.
echo $this->Form->create(); // Match with the filter configuration in your controller echo $this->Form->input('filter_id', ['type' => 'text']); echo $this->Form->input('filter_title', ['type' => 'text']); echo $this->Form->input('filter_category_id', ['options'=>[ /* ... */ ], 'multiple'=>'multiple' ]); echo $this->Form->button('Filter', ['type' => 'submit']); echo $this->Form->end();
Filter options
The following options are supported:
field(string) The name of the field to use for searching.operator(string) The operator used for searching.explode(boolean) Used only with operatorLIKEandILIKEto explode the string query.
Operators
The following options are supported:
=><>=<=LIKEILIKEIN
Persisting query (session)
All query strings are persisted using sessions. Make sure to load the Session component.
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-01-15