Thursday, February 27, 2014

Routing and controllers over ZF2


In the Zend Framework 1 Bibel "Zend Framework 1.8 Web Application Development" by Keith Pope the ZF1 request handling is described as follows:
The process can be broken down like this:
  1. A request is made and the Request Object is created.
  2. The routeStartup event is fired.
  3. The Router processes the request.
  4. The routeShutdown event is fired.
  5. The dispatchLoopStartup event is fired.
  6. The dispatch loop is started.
  7. The preDispatch event is fired.
  8. The Dispatcher calls the Action Controller.
  9. The Action Controller writes to the Response Object.
  10. The postDispatch event is fired.
  11. If there are actions left to call, then go to Step 7.
  12. The dispatchLoopShutdown event is fired.
  13. The Response is sent back.


zf2.


The mapping of a URL to a particular action is done using routes that are defined in the module’s module.config.php


The default route configured is to accept any url of this format, this is the standard format
mydomain.com/
mydomain.com/applicatiom/controller/action (standard format)
in your case mydomain.com/otheraction the router expect a module otheraction, but its not present.
if you need to have a route as specified above have a entry under route
'otheraction' => array(
    'type' => 'Zend\Mvc\Router\Http\Literal',
    'options' => array(
        'route'    => '/otheraction',
        'defaults' => array(
            'controller' => 'Application\Controller\Index',
            'action'     => 'otheraction',
        ),
    ),
),


http://framework.zend.com/manual/2.0/en/user-guide/routing-and-controllers.html