1

我有一个带有搜索输入的表单:

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);
}
}

这适用于结果的第一页,但在我看来,我有上一个/下一个助手,单击转到第二页只会打开一个空白页面。我如何保留搜索词并能够转到第二页?

4

1 回答 1

0

The Paginator::sort method uses a get to pass the parameters, you should pass the search term as GET then in your view, before you call the pagination links try this:

$this->Paginator->options = array(
    'url' => $this->passedArgs
);

That should have your search term persist with your pagination links.

于 2013-03-28T04:11:34.193 回答