I am trying to search between two prices using cakedc search plugin here is my model code:
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) ;
}
}
code for my controller:
public function index() {
$this->Prg->commonProcess();
$cond = $this->Property->parseCriteria($this->passedArgs);
$this->set('properties', $this->paginate('Property', $cond));
}
code for my view:
<?php
echo $this->Form->create();
echo $this->Form->input('minPrice');
echo $this->Form->input('maxPrice');
echo $this->Form->submit(__('Submit'));
echo $this->Form->end();
?>
table 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;