tags:

views:

575

answers:

4

Hi, 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 like domain.com/search/page:x, so in the next and prev and numbers page the get parameter ist lost. I need to configure paginator to get links like domain.com/search/page:x/?s=keyword But I can't do this. I need to know how to configure $paginator->options(); $paginator->next(); $paginator->prev(); $paginator->numbers();

to get the needed efect. Thanx.

A: 

Basically you can do it like this:

function list_results($keywords)
  {
  $data = $this->paginate('Posts', array('Post.title LIKE' => '%'.$keywords.'%'));
  }
PawelMysior
Sorry Paweł, you don't understand me.I have the $data in my view but only in page one, if I go to page 2 I go to domain.com/search/page:2 because $paginator in the view generate links like this, so the get "s" value is not present in my controller, if I go to domain.com/search/page:2/?s=keyword I've got the 2 page of the search result.I don't know how to force $paginator to generate links like domain.com/search/page:x/?s=keyword
Jos
Oh, yeah, I get what you mean now. Well I would like to see the solution to this as well. One thing you can do is use the session component to carry the keyword through pages. It does have some disadvantages though (can't give a link to someone).
PawelMysior
+5  A: 

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 :)

matyas
+1  A: 

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/view/166/Pagination-in-Views

dan rizz
A: 

http://q2interactive.net/view/retain-get-parameters-in-the-url-when-using-cakephp-paginator.html#comment-69

I used it, it works fine.

in app_controller file:

function _paginatorURL() { $passed = ""; $retain = $this->params['url']; unset($retain['url']); $this->set('paginatorURL',array($passed, '?' => http_build_query($retain))); }

function beforeFilter()
{

    $this->_paginatorURL();
    }

in views file:

  <?php $paginator->options = array( 'url' => $paginatorURL );?>

Hope it helps.

Bảo Nam