You may sometimes want to route forward appended URIs to its last corresponding action.
For example:
http://www.sample.com/mycontroller/login/ (WILL NOT route to login action)
http://www.sample.com/mycontroller/login (WILL ROUTE to login action)
http://www.sample.com/mycontroller/ (WILL NOT ROUTE to index action)
http://www.sample.com/mycontroller (WILL ROUTE to index action)
And assume this Route setting for above:
array(
'mycontroller' => array(
'type' => 'Segment',
'options' => array(
'route' => '/mycontroller',
'defaults' => array(
'controller' => 'SomeModule\Controller\MyController',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'login' => array(
'type' => 'Segment',
'options' => array(
'route' => '/login',
'defaults' => array(
'controller' => 'SomeModule\Controller\MyController',
'action' => 'login',
),
),
'may_terminate' => true,
),
),
),
);
To make the forward appended slashes default to the last action in the URI:
array(
'mycontroller' => array(
'type' => 'Segment',
'options' => array(
'route' => '/mycontroller',
'defaults' => array(
'controller' => 'SomeModule\Controller\MyController',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:action][/]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]+',
),
'defaults' => array(
'controller' => 'SomeModule\Controller\MyController',
'action' => 'index',
),
),
'may_terminate' => true,
),
'login' => array(
'type' => 'Segment',
'options' => array(
'route' => '/login[/]',
'defaults' => array(
'controller' => 'SomeModule\Controller\MyController',
'action' => 'login',
),
),
'may_terminate' => true,
),
),
),
);
Notice that I added a "default" child route so that I will not have to worry if a I added a new action and forget to create a route for it. Also notice the "[/]" which
means that forward slashes are optional now and that's basically it. You just have to add "[/]" in each route of a Segment type.
http://www.sample.com/mycontroller/login/ (WILL ROUTE to login action)
http://www.sample.com/mycontroller/login (WILL ROUTE to login action)
http://www.sample.com/mycontroller/ (WILL ROUTE to index action)
http://www.sample.com/mycontroller (WILL ROUTE to index action)
If you dont want a default fallback route, you can do just so.
array(
'mycontroller' => array(
'type' => 'Segment',
'options' => array(
'route' => '/mycontroller[/]',
'defaults' => array(
'controller' => 'SomeModule\Controller\MyController',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'login' => array(
'type' => 'Segment',
'options' => array(
'route' => '/login[/]',
'defaults' => array(
'controller' => 'SomeModule\Controller\MyController',
'action' => 'login',
),
),
'may_terminate' => true,
),
),
),
);
Notice that I added "[/]" in the parent route because we removed the default child fallback route.
Now your route with forward slashes should work.