ZF2-317: Controller not found automagically..

Description

The docs mention this:

"ZendSkeletonApplication ships with a "default route" that will likely get you to this action. That route basically expects "/{controller}/{action}", which allows you to specify this: "/zend-user-hello/world". We're going to create a route here mainly for illustration purposes, as creating explicit routes is a recommended practice. The application will look for a Zend\Mvc\Router\RouteStack instance to setup routing. The default generated router is a Zend\Mvc\Router\Http\TreeRouteStack. "

Only with me the route is never found untill i add the controller in the module config:

'controller' => array( 'classes' => array( 'My-App-Index' => 'MyApp\Controller\IndexController', ), )

Am not sure if this is supposed to be like this or if this is a bug?

Comments

Can you add your routes, controller and Di configuration ?

With default route, ControllerLoader find a "index" controller, you must write Di alias or an "index" key in "controller" configuration.

If you just add


'My-App-Index' => 'MyApp\Controller\IndexController',

Your app can't work.

Actually it does work with beta 4 with only this. But the documentation has a note: http://packages.zendframework.com/docs/latest/…

"Note ZendSkeletonApplication ships with a "default route" that will likely get you to this action. That route basically expects "/{controller}/{action}", which allows you to specify this: "/zend-user-hello/world". We're going to create a route here mainly for illustration purposes, as creating explicit routes is a recommended practice. The application will look for a Zend\Mvc\Router\RouteStack instance to setup routing. The default generated router is a Zend\Mvc\Router\Http\TreeRouteStack."

Which does not mention adding the controller to the configuration first before it can be found by the default route, which is confusing as ZF 1 will load controllers automatically not needing to add them to the config first.

Yes i understand this part is in the controller confguration but i think you are missing my point. My point is that the documentation is misleading as it explains that the default route will take me to this controller and action. Which it cannot untill i add it to the configuration. It would be better to add this to the documentation so it is less confusing for end users.

Ok you use a configuration like :


'defaults' => array(
      'controller' => 'My-App-Index',
            'action'     => '???',
),

So if you defined


'My-App-Index' => 'MyApp\Controller\IndexController',

it's work ok. But without that, app cannot work, because ControllerLoader (based on ServiceManager) don't know what is the controller associated to 'My-App-Index' identifier.

Evan Coury work on a feature based on the route /module/controller/action and i think this feature will resolve this problem.

This issue has been closed on Jira and moved to GitHub for issue tracking. To continue following the resolution of this issues, please visit: https://github.com/zendframework/zf2/issues/2484