我正在使用搜索插件https://github.com/cakedc/search。我正在嘗試僅使用ID字段搜索記錄,也就是說,如果我在表單輸入中輸入1,它必須顯示帶有用戶標識1的記錄。我現在面臨的挑戰是當我指定輸入應該是id字段,搜索功能的輸入字段在我的索引視圖中消失,奇怪的是當我指定輸入字段顯示的不同字段名稱時。搜索功能無法使用ID字段輸入
下面是我爲我的模型
public $actsAs = array('Search.Searchable');
public $filterArgs = array(
'id' => array('type' => 'like', 'field' => 'ItSupportRequest.id'),
);
public function findByTags($data = array()) {
$this->Tagged->Behaviors->attach('Containable', array('autoFields' => false));
$this->Tagged->Behaviors->attach('Search.Searchable');
$query = $this->Tagged->getQuery('all', array(
'conditions' => array('Tag.name' => $data['tags']),
'fields' => array('foreign_key'),
'contain' => array('Tag')
));
return $query;
}
public function orConditions($data = array()) {
$filter = $data['filter'];
$cond = array(
'OR' => array(
$this->alias . '.id LIKE' => '%' . $filter . '%',
));
return $cond;
}
這裏是我的控制器代碼的代碼。
public $components = array('Search.Prg');
public $presetVars = true; // using the model configuration
public function find() {
$this->Prg->commonProcess();
$this->paginate['conditions'] = $this->ItSupportRequest->parseCriteria($this->passedArgs);
$this->set('articles', $this->paginate());
}
和我index.ctp文件我有這樣的代碼。
<?php
echo $this->Form->create('ItSupportRequest', array(
'url' => array_merge(array('action' => 'find'), $this->params['pass'])
));
echo $this->Form->label('Query ID:') . "<br/>";
echo $this->Form->input('name', array('div' => false, 'label' => false));
echo $this->Form->submit(__('Search'), array('div' => false));
echo $this->Form->end();
?>
在此先感謝。
我不看到任何「ID」 - 只有「名稱」 – mark 2013-02-18 14:37:43