cakePHP - Slug with array of named arguments -
i abit stuck try figure out how can use slug on url array of named arguments:
the url follows: /controller/action/param:1-slug1/param:2-slug2/param:3-slug3
this gives me following named params array in request object:
[named] => array ( [param] => array ( [0] => 1-slug1 [1] => 2-slug2 [2] => 3-slug3 ) )
how configure route take slug consideration? such output is:
[named] => array ( [param] => array ( [0] => 1 [1] => 2 [2] => 3 ) )
thanks help.
firstly, don't need [0], [1]
stuff, naming parameters same, automatically create array. change url
/controller/action/param:1-slug1/param:2-slug2
your route following,
router::connect('/:controller/:action/*');
by passing star @ end route automatically pass through params have added. allow pass many parameters url want.
if want use named parameter route this.
router::connect('/:controller/:action:/:slug', array(), array('slug' => '[a-z0-9-]+'));
which match slug against regex in order make matching route. regex allows letters, numbers , hyphens.
read more here, http://book.cakephp.org/2.0/en/development/routing.html#passing-parameters-to-action
Comments
Post a Comment