我目前正在尝试找出一种在我的应用程序中实现 cakeDC 搜索插件的方法,但我发现很难理解需要完成的管道,然后才能让它(很好地)与我的应用程序一起工作。
需要考虑的事项: 搜索需要是“实时搜索” 检索到的记录需要分页 搜索将使用选定的标准(id、名称等实际键而不是值)完成,并且需要用户输入,我们将现在叫'查询'..
到目前为止,这是我的代码。
型号代码:
public $filterArgs = array(
'query' => array('type' => 'query', 'method' => 'filterQuery'),
);
public function filterQuery($data = array()) {
$filter = $data['query'];
$criteria = $data['criteria'];
if(empty($filter)){
return array();
}
$cond = array(
'OR' => array(
$this->alias . $criteria. 'LIKE' => '%' . $filter . '%',
//ie. criteria represents a field $ filter is the data to search/match
));
return $cond;
}
所以我遇到的问题是,我的 filterQuery 方法将如何接收 $data 参数。它是正常的请求数据吗?我想访问提交的两个值。
这是视图的相关代码:
<div id="search-container">
<?php
//echo $this->Form->create(false,array('type'=>'post','default'=>false));
echo $this->Form->input('criteria',array(
'label'=>'Search Criteria',
'options' => array(
'id'=> 'By ID',
'name' => 'By Name',
'blood_group_id' => 'By Blood Type',
'type' => 'By Donor Type',
'age' => 'By Age',
'gender' => 'By Gender'
)
));
?>
<?php echo $this->Form->input('query', array('type' => 'text', 'id' => 'query', 'name' => 'query', 'label' => false, 'placeholder' => 'Search')); ?>
[编辑]
当然在我的控制器中我也有这个设置
Search.Prg Component is loaded
public $presetVars = array(
'query' => array('type' => 'value'),
'criteria' => array('type' => 'value'),
);
任何帮助表示赞赏,即使它只是一个教程的链接。谢谢