如何在yii2中搜索过滤器multipe关系表和分组 [英] how to search filter multipe relation table and groupping in yii2

查看:216
本文介绍了如何在yii2中搜索过滤器multipe关系表和分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个表,比如 ridersPoint(id,nameRider,serie_id,point)和系列(serie_id,nameSerie,location,date,season_id) season(season_id,nameSeason,year)
属性 serie_id riderPoint 表中与 serie_id 系列表中,以及在系列中的属性 season_id 表与 season_id season 表中有关系。
如何在 riderPoint 中通过 season_id 进行搜索?当数据表在同一个季节中时如何分组点?
请帮助我。

解决方案

在gridview中搜索(过滤和排序)相关的字段是一系列的行动..你可以在这个文档中找到一些示例

http://www.yiiframework.com/wiki/653/displaying-sorting-and-filtering-model-relations-on-a -gridview /



简介..




  • 模型在(main / pivot)模型中定义您的活动关系并添加相关字段的getter
  • 在您的dataProvider的modelSearch中添加var fo相关字段,设置适当的排序顺序新增相关字段,在搜索功能中添加关系,并在modelSearch条件中添加适当的过滤器。
  • 将新属性添加到gridview。


    在提供的链接中深入观察场景2,您可以找到wha你需要

    I have three tables like ridersPoint (id, nameRider, serie_id, point) and series (serie_id, nameSerie, location, date, season_id) and season (season_id, nameSeason, year). Attribute serie_id in riderPoint table have relation with serie_id in series table, and Attribute season_id in series table have relation with season_id in season table. How to make search by season_id in riderPoint? And how to groupping point when have data table in the same season? Please help me..

    解决方案

    Search (filter and sort) for related field in gridview is base an a series of action.. you can find some sample in this doc

    http://www.yiiframework.com/wiki/653/displaying-sorting-and-filtering-model-relations-on-a-gridview/

    in brief..

    • In your model define your active relation in (main/pivot) model and add the getter for related field
    • In your modelSearch in your dataProvider add the var fo related field, set the proper sort for sorting by new related field, add the relation in search function and adding proper filter in modelSearch condition
    • Add the new attribute to the gridview..

    Take a deep look to the scenario 2 in the link provided.. and you can find what you need

    这篇关于如何在yii2中搜索过滤器multipe关系表和分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆