Search code examples
phpzend-frameworkroutesrouterzend-controller-router

Zend - routing rules based on parameters number


in my project I'm using zend to handle routing. Atm we've got routing rules which looks like this: array( 'match' => 'page', 'params' => array('page', 'idConfiguration'), 'controller' => 'controler1', 'action' => 'action1' )

So we access this action by: http://base_url/page/1/1223324 for example.

Is there a simple solution to create rules so i can determine which action is called based on number of params?

I'd like it to look the following way: http://base_url/ - action 0 http://base_url/pageNumber - action 1 http://base_url/pageNumber/idConfiguration - action 2 http://base_url/pageNumber/idConfiguration/someotherparam - action 3

Thank you in advance for help


Solution

  • Ini-based solution (hope I understand what you want):

    routes.action0.route = "/:pageNumber"
    routes.action0.defaults.controller = "controller0"
    routes.action0.defaults.action = "action0"
    routes.action0.reqs.pageNumber = "\d+"
    
    routes.action1.route = "/:pageNumber/:idConfiguration"
    routes.action1.defaults.controller = "controller1"
    routes.action1.defaults.action = "action1"
    routes.action1.reqs.pageNumber = "\d+"
    routes.action1.reqs.idConfiguration= "\d+"
    
    routes.action2.route = "/:pageNumber/:idConfiguration/:someOtherParam"
    routes.action2.defaults.controller = "controller2"
    routes.action2.defaults.action = "action2"
    routes.action2.reqs.pageNumber = "\d+"
    routes.action2.reqs.idConfiguration= "\d+"
    routes.action2.reqs.someOtherParam = "someOtherRegEx"