I have a problem with zf2 routing. I use the skeletal example https://github.com/zendframework/ZendSkeletonApplication/blob/master/module/Application/config/module.config.php , but when I contact to access http://localhost/admin/or http://localhost/admin/answers, I get a 404 message with the message:
A 404 error occurred
Page not found.
The requested controller could not be mapped to an existing controller class.
Controller:
Index(resolves to invalid controller class or alias: Index)
No Exception available
From the error message, I think the router is ignoring __NAMESPACE__. Maybe someone can help me find a solution to my problem?
I used https://github.com/zendframework/ZFTool to create the module and controllers. My file structure:
module/Admin
βββ config
β βββ module.config.php
βββ Module.php
βββ src
β βββ Admin
β βββ Controller
β βββ AnswersController.php
β βββ IndexController.php
βββ view
βββ admin
βββ answers
β βββ index.phtml
βββ index
βββ index.phtml
My module.config.php:
return array(
'controllers' => array(
'invokables' => array(
'Admin\Controller\Answers' => 'Admin\Controller\AnswersController',
'Admin\Controller\Index' => 'Admin\Controller\IndexController',
),
),
'router' => array(
'routes' => array(
'admin' => array(
'type' => 'literal',
'options' => array(
'route' => '/admin',
'defaults' => array(
'__NAMESPACE__' => 'Admin\Controller',
'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(
),
),
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'admin' => __DIR__ . '/../view',
),
),
);
If I change: '\__NAMESPACE__' => 'Admin\Controller', 'controller' => 'Index',- 'controller' => 'Admin\Controller\Index'I can access the index controller, but not the answers.
Additional Information:
. , . localhost/application/index localhost/application/answers, . ( ), config . - ? , ?
Zend Framework 2.2.4.