Wednesday 11 September 2013

Unable to set named parameter with CakePHP

Unable to set named parameter with CakePHP

I'm using the CakePHP pagination helper with a custom route however it
seems to be ignoring the page number. I believe this is because the named
parameter page doesn't exist in the request, which I've verified using
debug($this->request->params);:
array(
'plugin' => null,
'controller' => 'things',
'action' => 'index',
'named' => array(),
'pass' => array(),
'page' => '2'
)
As you can see, it's putting page outside of the named array. This is the
route I've defined for the custom pagination URLs:
Router::connect('/things/:page', array('controller' => 'skins', 'action'
=> 'index'), array('page' => '[0-9]+'));
Obviously, this means that no matter what page number I click on only the
first results show.
How can I modify the route to insert the page into the named parameters
array properly? I'd rather not directly modify
$this->request->params['named'] from the controller directly.

No comments:

Post a Comment