0
votes

I have an app I'm working on at the moment with some pretty strange routing involving passed args. Everything works fine, links are reverse routed correctly except for pagination. I'm tearing my hair out but must be missing something.

My routes are:

Router::connect('/manufacturer/:manufacturer/:friendly0', array('controller'=>'categories', 'action'=>'view'), array('pass'=>array('manufacturer', 'friendly0')));
Router::connect('/manufacturer/:manufacturer/:friendly0/:friendly1', array('controller'=>'categories', 'action'=>'view'), array('pass'=>array('manufacturer', 'friendly0', 'friendly1')));
Router::connect('/manufacturer/:manufacturer/:friendly0/:friendly1/:friendly2', array('controller'=>'categories', 'action'=>'view'), array('pass'=>array('manufacturer', 'friendly0', 'friendly1', 'friendly2')));
Router::connect('/manufacturer/:manufacturer/:friendly0/:friendly1/:friendly2/:friendly3', array('controller'=>'categories', 'action'=>'view'), array('pass'=>array('manufacturer', 'friendly0', 'friendly1', 'friendly2', 'friendly3')));
Router::connect('/manufacturer/:manufacturer/:friendly0/:friendly1/:friendly2/:friendly3/:friendly4', array('controller'=>'categories', 'action'=>'view'), array('pass'=>array('manufacturer', 'friendly0', 'friendly1', 'friendly2', 'friendly3', 'friendly4')));

and I have added the passed args to the Paginator options like this:

$this->Paginator->options(array('url'=>array(
    'controller' => 'categories',
    'action' => 'view',
    'manufacturer' => 'nsm',
    'friendly0' => 'Accessories'
)));

However, paginator links come out like this:

/categories/view/page:2/manufacturer:nsm/friendly0:Accessories

They should be:

/manufacturer/nsm/Accessories/page:2

Can anyone help?

Thanks in advance.

Edit:

If I add /* to the end of each route then pagination links and regular links work as expected but for the first route only. I'm guessing that when other routes should be matched during dispatch the first route is always true due to the /*.

Interestingly, if I change the order of these routes like this:

Router::connect('/manufacturer/:manufacturer/:friendly0/:friendly1/*', array('controller'=>'categories', 'action'=>'view'), array('pass'=>array('manufacturer', 'friendly0', 'friendly1')));
Router::connect('/manufacturer/:manufacturer/:friendly0/*', array('controller'=>'categories', 'action'=>'view'), array('pass'=>array('manufacturer', 'friendly0')));

Then Cake seems to think that the page:2 named param should be a passed arg and passes it to friendly:1.

1
I'd recommend changing your route configurations as answered in your other questions and seeing if paginator still gives any problems... - Shaz Amjad

1 Answers

0
votes

Answer to this question helped fix my problem. Thanks Shaz.

Consolidate CakePHP routes