CakePHP pagination and the get parameters

前端 未结 8 561
逝去的感伤
逝去的感伤 2021-02-02 02:31

I have a problem with the pagination in my search page. When a user search something I have a url like domain.com/search/?s=keyword but paginator gives me links lik

相关标签:
8条回答
  • 2021-02-02 03:02

    I know this is old but found a simple solution that works for me. Add following in view file -

    $paginator->options(array('url' => array_merge($this->passedArgs,
    array('?' => ltrim(strstr($_SERVER['QUERY_STRING'], '&'), '&')))));
    

    Found it here

    0 讨论(0)
  • 2021-02-02 03:05

    I used Matyas solution, but for $keyword I did like this:

    $queryString = explode('?', $_SERVER['REQUEST_URI']);
    $options = array('url'=> array('controller' => 'post', 'action' => 'search', '?' => $queryString[1]));
    
    0 讨论(0)
  • 2021-02-02 03:07

    To pass all URL arguments to paginator functions, add the following to your view: Plain Text View

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

    That's it. See http://book.cakephp.org/2.0/en/core-libraries/components/pagination.html

    0 讨论(0)
  • 2021-02-02 03:08

    create the options array

    $options = array(
        'url'=> array(
            'controller' => 'posts', 
            'action' => 'search', 
            '?' => 'keyword='.$keyword
         )
    );
    

    set it to the helper

    $paginator->options($options)
    

    and then you can use the paginator helper while retaining the GET variables.

    hope that it helped :)

    to make it easier you can putl $paginator options in your view or .ctp file

    $this->Paginator->options['url']['?'] = $this->params['ur];
    

    then put the value that you want :)

    0 讨论(0)
  • 2021-02-02 03:12
    $this->Paginator->options['url']['?'] = ['key' => $this->params['url']['value']];
    
    0 讨论(0)
  • 2021-02-02 03:13

    Basically you can do it like this:

    function list_results($keywords)
      {
      $data = $this->paginate('Posts', array('Post.title LIKE' => '%'.$keywords.'%'));
      }
    
    0 讨论(0)
提交回复
热议问题