我通過這條指令http://www.yiiframework.com/wiki/653/displaying-sorting-and-filtering-model-relations-on-a-gridview/ 完成了我的網格工作。但現在我需要有兩列與一列相關的數據。例如,在person/index中,gridView必須顯示City表中相關記錄的cityName和cityRegion。Yii2在GridView中顯示來自一個關係的多個值
我設法顯示數據,但無法使搜索功能正常工作。
在從鏈接的例子中,在函數搜索結束()有
$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])
...但我不不知道如何獲得實際的搜索值(在本例中是名稱和地區)。
謝謝!
編輯* 這裏是整個搜索()和規則定義:http://pastebin.com/mUVDYNiH 目前prod_ProductCode和prod_Manufacturer的排序工作,但對他們的搜索框顯示不出來。
發佈您的整個搜索()。 – 2015-02-23 13:35:43