codiverum/yii2-relation-search-filter 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

codiverum/yii2-relation-search-filter

最新稳定版本:1.0.7

Composer 安装命令:

composer require codiverum/yii2-relation-search-filter

包简介

Simple extension for making searching and filtering by related field simple.

README 文档

README

Simple extension for making searching and filtering by related field simple.

Use this trait to easily add ability to display/filter by related entity attribute. It also allows to use table aliases. Extension is pretty simple but makes the code cleaner, especially when using aliases (there are some auto-formatting bugs in some IDEs).

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist codiverum/yii2-relation-search-filter "*"

or add

"codiverum/yii2-relation-search-filter": "*"

to the require section of your composer.json file.

Usage

To use the trait you need to do the following (first example without using aliases):

  1. In top of your class (search-model) body put:
use \codiverum\relationSF\RelationSFTrait; 
  1. Make new public attribute in your class:
public $relation_name;
  1. Add your attribute to safe attributes
  2. In your search function add following:
  • after creating $query add:
$this->joinWithRelation($query, 'relation_name');
  • after creating $dataProvider add:
$this->addRelationSort($dataProvider, 'relation_name', 'related_table_field_name', 'table_name');
  • after creating query filters add:
$this->addRelationFilter($query, 'relation_name', 'related_table_field_name', 'table_name');
  1. Add to GridView columns array:
[
  'attribute' => 'relation_name',
  'value' => 'relation_name.related_table_field_name',
],

That's it.

Advanced Usage (with table aliases)

  1. In top of your class (search-model) body put:
use \codiverum\relationSF\RelationSFTrait; 
  1. Make new public attribute in your class:
public $relation_name;
  1. Add your attribute to safe attributes
  2. In your search function add following:
  • after creating $query add:
$this->joinWithRelation($query, 'relation_name', 'table_name', 'alias');
  • after creating $dataProvider add:
$this->addRelationSort($dataProvider, 'relation_name', 'related_table_field_name', 'alias');
  • after creating query filters add:
$this->addRelationFilter($query, 'relation_name', 'related_table_field_name', 'alias');
  1. Add to GridView columns array:
[
  'attribute' => 'relation_name',
  'value' => 'relation_name.related_table_field_name',
],

That's it.

统计信息

  • 总下载量: 438
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-4-Clause
  • 更新时间: 2015-09-22