fabrazer / yii2-helpers
0.0.4
2018-12-07 15:47 UTC
Requires
- php: >=5.4.0
README
功能
-
在 GridView 中显示、排序和过滤模型关系
EnableRelatedModelSearch 特性用于轻松地在 GridView 中通过模型关系实现显示、排序和过滤。
此特性执行以下链接中描述的任务:https://yiiframework.cn/wiki/653/displaying-sorting-and-filtering-model-relations-on-a-gridview
安装
$ php composer.phar require fabrazer/yii2-helpers "@dev"
用法
-
EnableRelatedModelSearch
-
启用特性
namespace app\models\search; use fabrazer\helpers\traits\EnableRelatedModelSearch; class TourSearch extends Tour { use EnableRelatedModelSearch; // Your code ... }
-
向您的搜索模型添加缺失的规则
public function rules() { $rules = [ // Your rules ]; // Add rules of the relations "city" and "country" $this->enableRelatedModelSearchRules(['city', 'country'], $rules); return $rules; }
-
添加缺失的属性
public function attributes() { // Add attributes of the relations "city" and "country" return $this->enableRelatedModelSearchAttributes(['city', 'country'], parent::attributes()); }
-
向查询中添加排序和过滤
public function search($params) { // Your code ... // Add sorting and filtering to the query $this->enableRelatedModelSearch(['city', 'country'], $dataProvider); }
-