Here is the standard router that I use for everything I port from ZF1 -> ZF2, remember that you still need to add the controllers as invocables, which I have at the top of the list. Also keep in mind that I always keep my actual application at the bottom of the list so that all other modules have their own routing defined before it gets to the application. However, this does the routing work just like ZF1 ... I see that many people ask about it, so I decided I would send it! With the setting below, I can simply add my new controller (support below ...) and then open a browser and go to ... / support, and it works fine.
return array( 'controllers' => array( 'invokables' => array( 'Application\Controller\Index' => 'Application\Controller\IndexController', 'Application\Controller\Support' => 'Application\Controller\SupportController', ), ), 'router' => array( 'routes' => array( '*' => array( 'type' => 'Segment', 'options' => array( 'route' => '/[:controller[/:action]]', /* OR add something like this to include the module path */ // 'route' => '/support/[: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', ), ), 'may_terminate' => true, 'child_routes' => array( 'wildcard' => array( 'type' => 'Wildcard' ) ) ), ), ), 'view_manager' => array( 'display_not_found_reason' => true, 'display_exceptions' => true, 'doctype' => 'HTML5', 'not_found_template' => 'error/404', 'exception_template' => 'error/index', 'template_map' => array( 'layout/layout' => __DIR__ . '/../view/layout/layout.phtml', 'application/index/index' => __DIR__ . '/../view/application/index/index.phtml', 'error/404' => __DIR__ . '/../view/error/404.phtml', 'error/index' => __DIR__ . '/../view/error/index.phtml', ), 'template_path_stack' => array( __DIR__ . '/../view', ), ), /* Service manager / translator etc stuff go HERE as they change less frequently */ );
I edited the route above to include the full path to the module as a comment, which I skipped in my original post.