Search code examples
zend-frameworkzend-controller-router

How do I write chains of chains of ... of route in a ini file for the Zend framework?


I am trying to define routes as below with an INI file for the Zend Framework: http://api.example.com/servicename/{version}/users/:userid/items/:itemid

routes.host.type = "Zend_Controller_Router_Route_Hostname"
routes.host.route = "api.example.com"

routes.host.chains.api.type = "Zend_Controller_Router_Route_Static"
routes.host.chains.api.route = "servicename/v1"
routes.host.chains.api.defaults.controller = "servicename-v1-api"
routes.host.chains.api.defaults.action = "index"

routes.host.chains.api.chains.users.chains.user.type = "Zend_Controller_Router_Static"
routes.host.chains.api.chains.users.route = "users"
routes.host.chains.api.chains.users.defaults.controller = "users"
routes.host.chains.api.chains.users.defaults.action = "index"

routes.host.chains.api.chains.users.chains.user.type = "Zend_Controller_Router_Route"
routes.host.chains.api.chains.users.chains.user.route = ":id"
routes.host.chains.api.chains.users.chains.user.defaults.controller = "user"
routes.host.chains.api.chains.users.chains.user.defaults.action = "index"
...

The host-api route works fine but when I try to reach the other routes, I get the error 'No route matched the request'

The chains.something.chains.somethingelse seems awkward so it probably isn't the correct way to do it. Anyone?


Solution

  • I think I have found how to do it. Basically, you define the parts of each routes with abstract set to true and link them all with routes whose type is set to Zend_Controller_Router_Route_Chain. Something like:

    [...]
    routes.users.type = "Zend_Controller_Router_Route"
    routes.users.route = "users"
    routes.users.abstract = "1"
    routes.users.defaults.controller = "users"
    routes.users.defaults.action = "index"
    
    routes.host-api-users.type = "Zend_Controller_Router_Route_Chain"
    routes.host-api-users.chains = "host, api, users"