2012-06-06 57 views
1

在Zend框架1,我可以做讓他們:如何獲取當前控制器的名稱和方法?

$this->actionName = $this->getRequest()->getActionName(); 
$this->controllerName = $this->getRequest()->getControllerName(); 

在Zend框架2我不知道。如何獲取controllerNameactionName

+0

你可以參考http://stackoverflow.com/questions/8843092/zf2-get-controller-name -into-layout-views –

回答

1

在控制器:

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

(二參數是默認值)

+0

有沒有辦法讓它們在__construct()方法中? – Developer

+0

你是什麼意思?它神奇地創造爲您的用法。它的類似於把它放在__construct() – michaelbn

相關問題