views:

493

answers:

2

Hello!

Is it possible in Zend View helper (extends Zend_View_Helper_Abstract) get info about module/controller/action in which that helper was called ?

+5  A: 

Yes. You can use Zend_Controller_Front::getInstance() within view helpers. So you could do something like this:

class App_Helper_DoSomething extends Zend_View_Helper_Abstract
{
    public function doSomething()
    {
        return Zend_Controller_Front::getInstance()->getRequest()->getControllerName();
    }
}

Which will print the current controller name when called in your view with

echo $this->doSomething();
Mark
A: 

This is to get the main request info. But what about a view called in a sub-request with helper $this->action() ?

I have several includes (menus, blocks ...) and I want to fetch the module, controller and action name where the helper was called, not the main one (front).

default/index/index.phtml --> $this->action('menu');
default/index/menu.phtml --> $this->someUsefulHelper();

someUsefulHelper(){
 return Zend_Controller_Front::getInstance()->getRequest()->getActionName();
}

Prints me 'index' and want 'menu'

Any idea ?

antoineg