我有一个问题,我想知道这是否是在 yii2 中编写 BETWEEN 查询的正确方法。
在我声明的控制器代码中$to_price
,这是我的 SearchModel 代码,但我总是得到与 for 相同的值null
,$this->to_price
以下是我的 search model
代码
public function search($params) {
$query = Events::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$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;
}
$query->joinWith(['eventsImages']);
$query->andFilterWhere([
'id' => $this->id,
'main_category_id' => $this->main_category_id,
'address' => $this->address,
]);
//$to_price = $params->to_price;
$query->andFilterWhere(['like', 'title', $this->title])
->andFilterWhere(['like', 'description', $this->description])
->andFilterWhere(['between', 'price', $this ->price, $this -> to_price])
->andFilterWhere(['like', 'image', $this->image]);
$command = $query->createCommand();// Created $command works fine in mysql
return $dataProvider; //But in $dataProvider it doesnt return any result
}
如果不是,我没有得到任何结果,但我可以看到生成的命令在mysql
所以这里有什么问题???