I am having an issue with zf2 routing. I am using skeleton example https://github.com/zendframework/ZendSkeletonApplication/blob/master/module/Application/config/module.config.php, but when I tying to access http://localhost/admin/ or http://localhost/admin/answers I am getting 404 with 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 error message I think router ignores __NAMESPACE__. Maybe someone could help me find solution to my problem?
I have used https://github.com/zendframework/ZFTool to create module and controllers. My file structure is:
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 am changing: '\__NAMESPACE__' => 'Admin\Controller', 'controller' => 'Index', to 'controller' => 'Admin\Controller\Index' I can access Index controller, but not Answers .
Additional info:
I found strange behavior of skeleton application. I have downloaded fresh skeleton application and this configuration works. If I am going to localhost/application/index or localhost/application/answers it works as accepted. But if I am changing Application module name to Admin and changing router configuration (replacing all application to admin and Application to Admin) and config stops working. Can anyone explain this? Maybe Application module works as default in skeleton applications?
I am using Zend Framework 2.2.4.
