开发者

CakePHP Search function with Paging Not Working

开发者 https://www.devze.com 2023-03-04 22:59 出处:网络
We are using CakePHP\'s default search behavior with listing page and once I have selected some criteria for searching, it works fine..

We are using CakePHP's default search behavior with listing page and once I have selected some criteria for searching, it works fine..

Now, whenever I go on page no. 2 with searched criteria, the search parameters does not pass with the Paging and it becomes a normal listing.

Do anyone have some idea about searching and paging combination, with CakePHP 1.2 default search plug-开发者_如何学Pythonin.

Let me know your responses ASAP.

Thanks !


Take a look at this tutorial. It looks vaguely like what I've done in the past.

http://mrphp.com.au/code/search-forms-cakephp


If you work with Sessions, then the search criteria could be stored in the session. You just need to make sure that the user also can easily reset the stored search criteria.

$this->paginate = array(
    'conditions' => array('Model.name LIKE' => '%'.$storedInTheSession.'%'),
    'order' => array('Model.name ASC'),
    );


Assuming that your form is created with 'type'=>'get'

echo $form->create('Content', array('action' => '/index', 'class' => 'forms','type'=>'get'));

you can do something like:

    if(isset($_GET['some_criteria'])){ //if some of you fields is set
        unset($_GET['url']); //this is set by CakePHP and we don't need it
        $paginator->options = array('url'=> array('controller' => 'content', 'action' => 'index', '?' => http_build_query($_GET)));
    }

Although it might suit your needs I warn you that it might not be the CakePHPiest way

0

精彩评论

暂无评论...
验证码 换一张
取 消