Cakephp 2.8为什么我的search_between函数会给我一个警告?

时间:2017-08-10 18:21:13

标签: cakephp search between

public function search_between() {

$min = $this->request->query['min'];
$max = $this->request->query['max']; 

$conditions = array('Ad.price BETWEEN ? AND ?' => array($min,$max));
$ads = $this->Anuncio->find('all',array('conditions' => $conditions));
$this->set('ads',$ads);

} 

警告:strlen()期望参数1为字符串,给定数组。

**Thank's for your help I'm new to asking questions here.**

2 个答案:

答案 0 :(得分:0)

试试这个:

public function search_between() {

$min = $this->request->query['min'];
$max = $this->request->query['max']; 

$conditions = array('Anuncio.price >=' => $min,'Anuncio.price <=' $max));
$ads = $this->Anuncio->find('all',array('conditions' => $conditions));
$this->set('ads',$ads);

答案 1 :(得分:0)

你可以使用Cakephp mysql查询它将像cakephp查询一样工作

if(!empty($min) && !empty($max)){
   $ads = $this->Anuncio->query('SELECT * from Anuncio WHERE Anuncio.price BETWEEN "'.$min.'" AND "'.$max.'"');
}

else{
$ads = $this->Anuncio->query('SELECT * from Anuncio');
}