Helo,有人能解释我为什么会收到这个错误吗?我正在做的是我正在尝试根据GridView
过滤我的id's
,但它会显示此错误消息。我试图搜索相关信息,但找不到有用的信息。
这是我的Search
功能:
public function search($params)
{
$query = Sale::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$query->joinWith('item');
$dataProvider->setSort([
'attributes' => [
'id',
'customer_name',
'customer_surname',
'customer_phone',
'customer_email',
'code',
'comment',
'sign',
'price' => [
'asc' =>['item.price' => SORT_ASC],
'desc' =>['item.price' => SORT_DESC],
],
'item_id' => [
'asc' =>['item.name' => SORT_ASC],
'desc' =>['item.name' => SORT_DESC],
]
]
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
]);
$query->andFilterWhere(['like', 'customer_name', $this->customer_name])
->andFilterWhere(['like', 'item.name', $this->item_id])
->andFilterWhere(['like','sign', $this->sign])
->andFilterWhere(['like', 'customer_surname', $this->customer_surname])
->andFilterWhere(['like', 'customer_phone', $this->customer_phone])
->andFilterWhere(['like', 'customer_email', $this->customer_email])
->andFilterWhere(['like', 'code', $this->code])
->andFilterWhere(['like', 'comment', $this->comment]);
return $dataProvider;
}
它应该有用,因为id
已添加到setSort()
和filter
语句中...感谢您的帮助
答案 0 :(得分:5)
它应该工作,因为你加入item
表,它可能有另一个id
列。改变这个:
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
]);
为:
// grid filtering conditions
$query->andFilterWhere([
'sale.id' => $this->id,
]);
另一种方法是为表使用别名。