Get request info in view helper
Asked Answered
F

1

14

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

Fukien answered 7/1, 2010 at 14:54 Comment(0)
R
34

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();
Relevant answered 7/1, 2010 at 16:4 Comment(2)
how would you get the module name? is that possible?Twocycle
chrisjlee : Zend_Controller_Front::getInstance()->getRequest()->getModuleName();Cusick

© 2022 - 2024 — McMap. All rights reserved.