我正在尝试使用paginator组件中的搜索来过滤配方。但它只搜索食谱表的标题栏。我希望它还可以搜索配方表的主体列和标签列。
在控制器中
$this->Paginator->settings = $this->paginate;
$this->Paginator->settings['limit']=$this->pageLimit;
$this->Paginator->settings['maxLimit']=$this->maxLimit;
$this->Paginator->settings['conditions'] = $this->Recipe->parseCriteria($this->Prg->parsedParams());
当我查看$this->Paginator->settings['conditions']
时,它看起来像这样
Array
(
[Recipe.title LIKE] => %chocolate%
)
我想扩展条件,以便更多地查看配方表的多个列,例如Recipe.title LIKE
,Recipe.body LIKE
和Recipe.tags LIKE
。
答案 0 :(得分:0)
您需要在模型中使用自定义功能。
public $filterArgs = array(
'filter' => array(
'type' => 'query',
'method' => 'orConditions'
),
);
public function orConditions($data = array()) {
$filter = $data['filter'];
$condition = array(
'OR' => array(
$this->alias . '.title LIKE' => '%' . $filter . '%',
$this->alias . '.body LIKE' => '%' . $filter . '%',
$this->alias . '.body LIKE' => '%' . $filter . '%',
)
);
return $condition;
}