2012/8/6 sina miandashti <[email protected]>

> hi
>
> im wondering
>
> why this returned null  in my onBootstrap method in module.php
>
> $e->getRouteMatch();
>
>
> i want to get requested controller and action in module.php
>

Hi Sine,

The onBootstrap listener listens to the "bootstrap" event. That is a part
of the process to initiate all modules of your application, independent of
what (kind of) request you are sending. The routing is another stage and
happens after bootstrapping.

If you need to fetch the controller and action, you create a listener in
your application for the route event. This listener will be attached during
bootstrap:

use Zend\EventManager\EventInterface;
use Zend\Mvc\MvcEvent;

class Module
{
    public function onBootstrap(EventInterface $e)
    {
        $app = $e->getApplication();
        $em  = $app->getEventManager();

        $em->attach(MvcEvent::EVENT_ROUTE, function($e) {
            $routeMatch = $e->getRouteMatch();

            $controller = $routeMatch->getParam('controller');
            $action     = $routeMatch->getParam('action');
        });
    }
}

This will give you the controller (as a string value, not the class itself)
and the action.

-- 
Jurian Sluiman

Reply via email to