0

Is it possible to get the current module/controller/action name from a view script? How can I do it?

1 Answer 1

0

You could retrieve it in your controller using the MvcEvent object and then assign it to the ViewModel so you can retrieve it in the view:

public function indexAction()
{
   return new ViewModel(
            array(
                'controller' => $this->getEvent()->getRouteMatch()->getParam('controller'),
                'action' => $this->getEvent()->getRouteMatch()->getParam('action')
            )
        );
}

The module name is a bit trickier, but you could for instance get it using the NAMESPACE or just parse it from the controller name.

If you want to use this in multiple views then it's probably better to create and register your own view-helper.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.