in zf1, we can get the name of the controller and action using
$controller = $this->getRequest()->getControllerName();
$action = $this->getRequest()->getActionName();
How can we achieve this in zf2?
UPDATE: I tried to get them to use
echo $this->getEvent()->getRouteMatch()->getParam('action', 'NA');
echo $this->getEvent()->getRouteMatch()->getParam('controller', 'NA');
But I get an error
Fatal error: Call to a member function getParam() on a non-object
I like to use them in the __construct () method;
Ideally, I would like to check if any action is defined, it will execute the noaction () method. I would check using method_exists php method.
source
share