routing - Consolidate CakePHP routes -


is there way consolidate following rules 1 rule?

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'))); 

actually - don't need use many rules:

http://book.cakephp.org/view/945/routes-configuration

essentially when browse yoursite.com/manufacturer - manufacturer controller called, , since action isn't defined - default index. just:

router::connect('/manufacturer/*', array('controller' => 'categories', 'action' => 'view')); 

now when browses yoursite.com/manufacturer - request forwarded categories controller, calling view action. '/*' insures further parameters forwarded there.

so when visit yoursite.com/manufacturer/iamfriendly/iamfriendlytoo - can passed paramaters / variables through

$this->params['pass'] 

or:

$this->passedargs 

giving following array:

array (     [0] => iamfriendly     [1] => iamfriendlytoo ) 

you can further enhance using named parameters, receive like:

array (     ['manufacturer'] => iamfriendly     ['friendly0'] => iamfriendlytoo ) 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -