Yii2在GridView中显示来自一个关系的多个值

时间:2015-02-23 13:26:56

标签: search yii2

我通过这条指令http://www.yiiframework.com/wiki/653/displaying-sorting-and-filtering-model-relations-on-a-gridview/完成了我的网格 它起作用了。但现在我需要有两列与一列相关的数据。例如,在person / index中,gridView必须从City表中的相关记录中显示cityName和cityRegion。

我设法显示数据,但无法使搜索功能正常工作。

在链接的示例中,在函数search()的末尾有

$query->andFilterWhere([
    //... other searched attributes here
])
// Here we search the attributes of our relations using our previously configured
// ones in "TourSearch"
->andFilterWhere(['like', 'tbl_city.name', $this->city])
->andFilterWhere(['like', 'tbl_country.name', $this->country]);

我想我应该有类似的东西:

->andFilterWhere(['like', 'tbl_city.name', $this->city])
->andFilterWhere(['like', 'tbl_city.region', $this->city])

...但我不知道如何获取实际搜索值(在本例中为名称和区域)。

谢谢!

编辑* 以下是整个search()和规则定义:http://pastebin.com/mUVDYNiH 目前prod_ProductCode和prod_Manufacturer的分类工作正常,但它们的搜索框没有显示。

1 个答案:

答案 0 :(得分:0)

点击yii2 ActiveQuery 'OR LIKE' filter

$查询 - > andFilterWhere([     '要么',     ['like','tbl_city.name',$ this-> city],     ['like','tbl_city.region',$ this-> city], ]);

相关问题