我正在使用搜索插件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