【发布时间】:2014-11-20 14:39:18
【问题描述】:
我正在尝试使用 CakeDC 的 Search plugin 实现搜索。在这个搜索中,我有一个设置了'multiple' => 'checkbox' 的字段。此字段允许用户选择多个城市,以便他们可以根据城市/城市过滤结果。我对此做了什么,我只是在Searchable Model 的$filterArgs 中为该字段指定了'type' => 'IN'。但注意到发生它只是响应所有结果,没有发生搜索/过滤。为了清楚地了解我在这里实现的是代码 sn-ps:
Model.php
public $actsAs = array(
'Search.Searchable'
);
public $filterArgs = array(
'city' => array(
'type' => 'in',
'field' => 'Model.city'
));
search_form.ctp
echo $this->Form->create('Model', array('url' => array('controller' => 'models', 'action' => 'search')));
echo $this->Form->input('city', array(
'multiple' => 'checkbox',
'options' => array(
'city1' => 'city1',
'city2' => 'city2',
'cityn' => 'cityn')
));
echo $this->Form->end('search');
ModelsController.php
public function search() {
$this->layout = 'front_common';
$this->Prg->commonProcess();
$this->Paginator->settings = array(
'conditions' => $this->Model->parseCriteria($this->Prg->parsedParams()),
'limit' => 10
);
$this->set('Data', $this->Paginator->paginate());
}
还有一次我尝试在ModelsController 中使用beforeFilter() 将city array() 与(,) 一起用于IN,但所有结果相同。我想问是否有任何其他插件可以做到这一点,或者是否有任何黑客可以使用 cakeDC 的搜索插件来做到这一点。请帮忙。
【问题讨论】:
-
我认为搜索插件不支持此功能。您最好只构建自己的过滤器。
-
@DavidYell 是的,我认为它不存在。可能是我们需要调整它以按照我们的意愿使用它,或者您可以建议任何方法以便我可以实现它..?
-
就我个人而言,我可能只是遍历请求数据并构建一个数组,我可以将它传递给我的查询中的“IN”条件。
-
@DavidYell 是的,我做了类似的事情,我最后也提到过,问题可能是我的实现错误..
标签: php cakephp cakephp-2.0 cakephp-2.5 cakephp-search-plugin