Question

I am using cakePHP and I am trying to get the paginator component to pass the get variables, or passedargs, when you click through to different pages. I have a variety of different search input selectors which "filters" the results returned. This works on first view, but the moment I click on a different page, it shows all of the results.

I have the following setup for my paginator:

// In my controller class:
public $paginate = array('maxLimit' => 10, 'paramType' => 'querystring');

// Within my action method:
$this->paginate = array('conditions' => array(...),
                        order => array('Model.field ASC'),
                        'limit' => 20 
 );

 // Calling the paginator:
 $results = $this->paginate('Model');
 $this->set(compact('results'));

In my view file:

 <div class="paging">
<?php
    echo $this->Paginator->prev('< ' . __('previous'), array(), null, array('class' => 'prev disabled'));
    echo $this->Paginator->numbers(array('separator' => ''));
    echo $this->Paginator->next(__('next') . ' >', array(), null, array('class' => 'next disabled'));
?>
</div>

EDIT: From my understanding it's better to use the passedArgs, but I am a little unsure as to how to do this. My $this->passedArgs returns no results, so I am creating the passed parameters within my controller example. I also changed my form from Get to Post:

 $this->passedArgs["searchfield"] = $_POST["value"];

It passes the passedArgs now correctly in the pagination strip, but I am unsure as to how to build the paging conditions array now. In most cases users will not select default values example, one of the filters is date from and date to, and then a search input box, if I leave the dates it will still created the argumens and not return any results so in essence my url would be something like:

 http://localhost/site/controller/action/page:3/datefrom:0/dateto:0/searchFor:survey

Any assistance?

Was it helpful?

Solution

You can pass by all parameters in the view with:

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

or assign the params manually:

$this->Paginator->options(array('url' => array("0", "1")));

befor echoing the paginator

See the CakePHP Cookbook for further Examples

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top