My Module's module.config.php
in Zend Framework 2 looks like this:
return array(
'controllers' => array(
'invokables' => array(
'Test\Controller\A' => 'Test\Controller\AController',
'Test\Controller\B' => 'Test\Controller\BController',
'Test\Controller\C' => 'Test\Controller\CController',
),
),
'router' => array(
'routes' => array(
'some-test' => array(
'type' => 'literal',
'options' => array(
'route' => '/a',
'defaults' => array(
'controller' => 'Test\Controller\A',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'some-other-test' => array(
'type' => 'segment',
'options' => array(
'route' => '[/:controller[/:action]]',
'defaults' => array(
'action' => 'index',
),
),
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
);
The literal route works, /a
is correctly matched, while /a/
results in a 404, which is fine & logical.
With the segment route, things look a bit differently. Regardless of what I enter, the route is never matched. So the route /a/b
fails and I don't understand.
According the the child route setup above, the trailing slash is optional, but when it's there, a controller name also needs to be specified. If this is the case, the index action of the specified controller should be called – in this example from the BController.
If a trailing slash is added after the controller name, an action needs to be specified.
Even when I enter /a/b/index
, I get a 404 error:
The requested controller could not be mapped to an existing controller class.
Controller:
b(resolves to invalid controller class or alias: b)
From this I conclude that the whole child route it not working, not only the default/fallback option. Why is the child route never matched?
'route' => '[/:controller[/:action]]',
->'route' => '/:controller[/:action]',
– Xerkus/a/b
? – Xerkus/a/b/index
says that your route works. So if you don't get same error for/a/b
then something strange happening – Xerkusinvokables
like this :'a' => 'Test\Controller\AController', 'b' => 'Test\Controller\BController', 'c' => 'Test\Controller\CController',
. I think it would work – blackbishop