我正在尝试使用 cakedc 搜索插件在两个价格之间进行搜索,这是我的模型代码:
public $actsAs = array(
'Search.Searchable'
);
public $filterArgs = array(
'price' => array(
'type' => 'expression',
'method' => 'makeRangeCondition',
'field' => 'Price.views BETWEEN ? AND ?'
)
);
public function makeRangeCondition($data = array()) {
if (strpos($data['price'], ' - ') !== false){
$tmp = explode(' - ', $data['price']);
$tmp[0] = $tmp[0] ;
$tmp[1] = $tmp[1] ;
return $tmp;
} else {
return array($minPrice, $maxPrice) ;
}
}
我的控制器的代码:
public function index() {
$this->Prg->commonProcess();
$cond = $this->Property->parseCriteria($this->passedArgs);
$this->set('properties', $this->paginate('Property', $cond));
}
我的观点的代码:
<?php
echo $this->Form->create();
echo $this->Form->input('minPrice');
echo $this->Form->input('maxPrice');
echo $this->Form->submit(__('Submit'));
echo $this->Form->end();
?>
表 sql:
CREATE TABLE IF NOT EXISTS `properties` (
id
varchar(36) NOT NULL,
price
float DEFAULT NULL, PRIMARY KEY ( id
), UNIQUE KEY ID
( id
) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;