我正在使用CakePHP搜索插件,並且有些事情我無法工作。我希望有一個搜索字段(我們稱之爲年齡),用戶可以在其中輸入一個值(例如24),並獲取表中所有年齡段字段中的值誰是24歲或更高。我怎樣才能做到這一點?CakePHP搜索插件,搜索等於或高於搜索中給定的值
到目前爲止,我可以通過名稱或一個確切的數值進行正常搜索,像(如果你想24歲正是然後正常工作)。
下面是與搜索插件,我到目前爲止的相關代碼:
- 型號:
class Person extends AppModel{
var $name = 'Person';
public $actsAs = array('Searchable');
public $filterArgs = array(
array('name' => 'name', 'type' => 'like'),
array('name' => 'age', 'type' => 'value'),
);
}
- 控制器:
class PersonsController extends AppController {
var $name = 'Persons';
var $components = array('Search.Prg');
public $presetVars = array(
array('field' => 'name', 'type' => 'value'),
array('field' => 'age', 'type' => 'value'),
);
function index() {
$this->set('persons', $this->Person->find('all'));
}
/* ---------------- SEARCH PLUGIN --------------*/
public function find() {
$this->Prg->commonProcess();
$this->paginate['conditions'] = this->Game->parseCriteria($this->passedArgs);
$this->set('persons', $this->paginate());
}
}
- 找到。 ctp:
與代碼上面,我可以perfomr搜索爲 歲場的精確值://apart from the code below, I have all the code to show the results
echo $form->create('Game', array(
'url' => array_merge(array('action' => 'find'), $this->params['pass'])
));
echo $form->input('name', array('div' => false));
echo $form->input('age', array('div' => false));
echo $form->submit(__('Search', true), array('div' => false));
echo $form->end();
綜上所述。如何更改該項以執行'age> = 值的搜索輸入'?
先謝謝你了!
O_o YW :)現在,請不要誤會我的意思,我喜歡像下一個開發者一樣漂亮的小抽象。也許我錯過了一些東西。你爲什麼不用Cake的神奇的findBy?不需要明確定義findByWhatever('field') - 只需調用它即可。當你滾動findByWhatever時,Cake的Model類會調用一個動態方法,接受'whatever',在Model的字段中查找,然後返回第一個。 (Betcha你無法猜測findAllByWhatever有什麼不同......^_ ^)findBy()/ findAllBy()不支持等於或大於比較嗎? – OpenSorceress