posted by admin
on Thu, 05/16/2013 - 14:41
ZF2 introduces a new routing for the framework which is similar to ZF1, but has slightly different semantics. The skeleton application ships with a default Application level router which takes matching controller/action to /application/controller/action URI. If you wish to keep it backward compatible with ZF1 type of matching, you may want to make the following changes to the module/Application/config/module.config.php file as below:
'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', ), ), ), ), ),
If you have other modules that matches "module" portion of the URI, don't worry. ZF2 is smart enough to handle multiple matches.
An alternative way to create a similar route is:
'home' => array( 'type' => 'Zend\Mvc\Router\Http\Literal', 'options' => array( 'route' => '/', 'defaults' => array( 'controller' => 'Application\Controller\Index', 'action' => 'index', ), ), 'may_terminate' => true, 'child_routes' => array( 'default' => 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( 'action' => 'index', '__NAMESPACE__' => 'Application\Controller' ), ), ), ), ),