How to add a new route in Zend Framework 2.5

In this tutorial I will explain how to add a new route in Zend Framework 2.5.

In the file module\Newapp\config\module.config.php add this code:


'router' => array(
'routes' => array(
'(the name of the route)' => array(
'type' => 'segment',
'options' => array(
'route' => '/theaddressofthepage',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*'
),
'defaults' => array(
'controller' => 'Newapp\Controller\Newapp(here is the controller name)',
'action' => 'index(and here is the action)',
),
),
),
),
),

To add another route, just copy this code:


'(the name of the route)' => array(
'type' => 'segment',
'options' => array(
'route' => '/theaddressofthepage',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*'
),
'defaults' => array(
'controller' => 'Newapp\Controller\Newapp(here is the controller name)',
'action' => 'index(and here is the action)',
),
),
),

You must also create a new action in your controller and a new view file.

Video tutorial:









Leave a Comment