Router for use with single module in Zend Framework 2
As you probably know, Zend Framework 2 basically forces you to use a module structure. This is fine, but for small projects it seems overkill and I'd rather just use a single - more ZF1 like - module that contains my whole application. This is actually quite easy to do. If you base your application on Zend's ZendSkeletonApplication, then you can build everything under the included 'Application' module. The only thing I changed was the router so that it acted as per the default router in ZF1. i.e. /:controller/:action
To do this you just need to amend the 'router' entry in Application/config/module.config.php so that it read as follows:
'router' => array( 'routes' => array( 'home' => array( 'type' => 'Segment', 'options' => array( 'route' => '/[:controller[/:action]]', 'constraints' => array( 'controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 'action' => '[a-zA-Z][a-zA-Z0-9_-]*', ), 'defaults' => array( '__NAMESPACE__' => 'Application\Controller', 'controller' => 'Index', 'action' => 'index', ), ), ), ), ),
This basically just extends the supplied 'home' router so that it allows a controller and action to be passed, which will be accessed under the 'Application\Controller' namespace.












