我有一个带有搜索输入的表单:
echo $this->Form->create('Job', array('url'=>array('controller'=>'jobs', 'action'=>'search'), 'action'=>'search', 'inputDefaults' => array( 'label' => false, 'div'=>false)));
echo '<br/>'.$this->Form->input('search', array( 'label' => false, 'div'=>false));
echo $this->Form->submit('Search', array('div' => false));
在我的控制器中我有像这样的分页数组:
public $paginate = array(
'Job' => array(
'fields' => array('Job.id', 'Job.name', 'Job.description', 'Job.tag_words'),
'limit' => 5,
'order' => array(
'Job.name' => 'asc'
)),
);
然后我的搜索功能是:
public function search () {
if ($this->request->is('post')) {
$conditions = array();
$search_terms = explode(' ', $this->request->data['Mix']['search']);
foreach($search_terms as $search_term){
$conditions[] = array('Mix.name Like' =>'%'.$search_term.'%');
$conditions[] = array('Mix.description Like' =>'%'.$search_term.'%');
$conditions[] = array('Mix.tag_words Like' =>'%'.$search_term.'%');
}
$searchResults = $this->paginate('Mix', array('Mix.published'=>1, 'OR' => $conditions));
$this->set('searchResults', $searchResults);
}
}
这适用于结果的第一页,但在我看来,我有上一个/下一个助手,点击进入第二页只会打开一个空页面。我打算如何保留搜索字词并能够转到第二页?
答案 0 :(得分:0)
Paginator :: sort方法使用get来传递参数,你应该在搜索分页链接之前将搜索词作为GET传递到你的视图中,试试这个:
$this->Paginator->options = array(
'url' => $this->passedArgs
);
您的搜索字词应该与您的分页链接保持一致。