2
votes

I have a table of Parts retrieved from a database and a form with a select tag listing PartTypes and a [Refresh] button. These are used to filter the table to show only parts that match the selected type.
The table is paginated for performance. When I start on Page 1, I can successfully filter my data table using my select and refresh button, but if I navigate away from page 1 via the Paginator, and try to refresh the page with a new PartType (rather than all being visible), I get the following error

Error: The requested address '/product/parts/index/page:2' was not found on this server.

I have been through the PaginatorComponent and PaginatorHelper documentation and cannot see how to reset the page before filtering my data. What am I missing?

/Controller/PartsController.php

public $paginate = array(
    'limit' => 12, 
    'page' => 1,
    'order' => array('Part.name' => 'asc' ) 
);

public function index() {
//  ...
    //  array $qcond holds the query properties for filtering parts
    if (count($qcond) > 0)
        $this->paginate['conditions'] = $qcond;

    //  ...
    $this->set('parts', $this->paginate());
}

app/View/Parts/index.ctp

<?php 
    echo $this->Paginator->prev(__('«'), array('tag' => 'li'), null, array('tag' => 'li','class' => 'disabled','disabledTag' => 'a'));
    echo $this->Paginator->numbers(array('separator' => '','currentTag' => 'a', 'currentClass' => 'active','tag' => 'li','first' => 1));
    echo $this->Paginator->next(__('»'), array('tag' => 'li','currentClass' => 'disabled'), null, array('tag' => 'li','class' => 'disabled','disabledTag' => 'a'));
?>

Problem solved: Issue was not in the Paginator, but in the Form. Had to manually set the form's url to not use /page:2, rather than let CakePhp deduce the url on it's own.

1

1 Answers

0
votes

In Cakephp 2.x You can reset page by using bellow code in Controller:

$this->request->params['named']['page']=1;