EddardOmeka
EddardOmeka

Reputation: 805

Generic Module Routing in Zend Framework 2

We are using ZF2 for a website project that has two modules, frontend and backend. We would like to generate URLs for both of those modules that have the following canonical form:

/module/controller/action

So far we tried this solution and we have not been able to make it work

'router' => array(
    'routes' => array(
        'application' => array(
            'type'    => 'Segment',
            'options' => array(
                'route' => '/[:module[/:controller[/:action]]]',
                'constraints' => array(
                    'module'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 
                    'action'     => '[a-zA-Z][a-zA-Z0-9_-]*'
                ),
                'defaults' => array(
                    'module'     => 'Front',
                    'controller' => 'Front\Controller\Index',
                    'action'     => 'index'
                )
            )
        ),
    ),
),

We would like the URL to look like /modulename/controllername without the need to create specific routes for each module similar to the old default route for ZF1. Is it possible to do that or is there a way specific to zf2?

Upvotes: 1

Views: 1778

Answers (1)

Chris
Chris

Reputation: 884

In the new ZF2 Beta5, there is a new listener Zend\Mvc\ModuleRouteListener, so you would have to add a __NAMESPACE__ key to your route, this will prepend the namespace to the Controller, and thus, you will have a generic route.

Upvotes: 2

Related Questions