WJBlog


Zend Framework Tip - Getting Controller and Action Names

Published On: August 23, 2010 @ 02:18:25pm

Although it’s possible to use multiple controller- and even action-specific layouts within your Zend Framework application, sometimes it can be easier to employ a bit of logic within a single layout in order to render custom content. In order to do so you’ll need to know which controller and action are currently executing, and then use an if-conditional to render the desired output. You can determine the names of the controller and action using the following static methods:

Get the action name:

Zend_Controller_Front::getInstance()->getRequest()->getActionName()

Get the controller name:

Zend_Controller_Front::getInstance()->getRequest()->getControllerName()