如何在 Zend Framework 2 中获取控制器名称、动作名称 [英] How to get the controller name, action name in Zend Framework 2

查看:31
本文介绍了如何在 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');

这篇关于如何在 Zend Framework 2 中获取控制器名称、动作名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆