Overriding module configuration in ZF2

Let's say that you install the ZF-Common's User module. By default, it sets up its routes under the /user path segment like this:


This config section will create the routes /user and through the magic of child_routes, also create /user/login and other required routes.

If you don't want /user and would prefer /member, then it's easy enough to change. Just add a new config file to the project's config/autoload folder:


As a result of using child_routes, all the other routes under this route will pick up the same segment, so /user/login is now accessed via /member/login. Also, as each route is named independently from its route, all the url view helper calls continue to work as the route's name continues to be zfcuser/login.

Obviously, this technique works for any other config setting that you may wish to override.

3 thoughts on “Overriding module configuration in ZF2

  1. Am I the only one who finds the zf2 config arrays incredibly hard to read and prone to spelling errors ?

  2. Brian, you are not.

    But it is better than having extensive caching framework for configuration files just because parsing them takes ages (looking oddly towards Symfony2).

    While I think they should be in PHP, they might not need be such a deeply nested array perhaps…

    But instead of inventing new configuration syntax, ship it!

Comments are closed.