如何在 Zend Framework 2 中获取控制器名称、动作名称

问题描述:

我在 Zend Framework 2 中有一个默认模块:

I have a default module in Zend Framework 2:

namespace Application\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

class IndexController extends AbstractActionController
{
    public function indexAction()
    {
        return new ViewModel();
    }
}

如何获取当前控制器的名称或操作名称...并将其传递给视图和/或布局?不得不说我刚开始接触ZF2框架.

How can I get the name of the current controller or action name ... and pass it to the view and/or layout? Have to say that I am just starting with the ZF2 framework.

ZF2 如下尝试

$this->getEvent()->getRouteMatch()->getParam('action', 'index'); 

$this->getEvent()->getRouteMatch()->getParam('controller', 'index');