phpzend-frameworkvariableszend-routezend-controller-router

Is there a way to change the route variable separator in Zend Framework?


I'd like to change the way URLs that Zend Framework is generating from this:

$routeString = '/section/:sectionName';
$route = new Zend_Controller_Router_Route(routeString, array( etc, etc... );

...to this...

$routeString = '/section_:sectionName';
$route = new Zend_Controller_Router_Route(routeString, array( etc, etc... );

Note that in the second option the middle slash in $routeString is replaced by an underscore.

When I make this change, the router stops recognizing the route and variables. I find it quite strange that the framework would impose such thing so I'm sure I'm missing something in the docs.

Cheers!


Solution

  • I think you could do it using Zend_Controller_Router_Route_Regex. As an example I'll provide setup for your route in the application.ini:

    resources.router.routes.section.type = "Zend_Controller_Router_Route_Regex" 
    resources.router.routes.section.route = "section_(\d+)"
    resources.router.routes.section.defaults.module = yourmodule
    resources.router.routes.section.defaults.controller = yourcontroller
    resources.router.routes.section.defaults.action = youraction
    resources.router.routes.section.map.1 = "sectionName"
    resources.router.routes.section.reverse = "section/%d"
    

    Hope this will help you or at least point you in the right direction.