Cakephp 2.x routing question

Hi

Is it possible to create a route with a wildcard “in the middle” which represents an unknown number of parameters when a named parameter is also at the end? The unknown parameters should be passed to $this-params->pass.

An example to make this a litte clearer. So the route is:

Router::connect(’/products/*/:section’, array(‘controller’ => ‘categories’,‘action’ => ‘sets’,‘language’ => ‘eng’),array(‘named’ => array(‘section’)));

So * represents a unknown count of parameters. It could be:

/products/cat1/cat2/cat3/:section

or

/products/cat1/:section

and so on.

This routing below would do the job, but it would be much nicer if the section is at the end.

Router::connect(’/products/:section/*’, array(‘controller’ => ‘categories’,‘action’ => ‘sets’,‘language’ => ‘eng’),array(‘named’ => array(‘section’)));

Hope this is possible…

Thanks,
Frank

It’s been a while since I’ve played with CakePHP, but I’m not sure that it would be possible in the form you have it at the moment.

As an alternative, just use ‘/products/*’ as the route, and have the controller inspect $this->request->params['pass'] or $this->passedArgs to determine the value of the last segment, which could be the section.

Usage of section as a named would need to have the URL looking like /products/cat1/section:MySection to extract the value of the section.