zend-framework, call an action helper from within

2019-02-05 18:38发布

i am writing an action helper and i need to call another action helper from within that helper. but i dont know how. here in the sample code:

class Common_Controller_Action_Helper_SAMPLE extends Zend_Controller_Action_Helper_Abstract
{
    protected $_view;
    public function __construct(Zend_View_Interface $view = null, array $options = array())
    {
        $this->_view = $view;
    }

    public function preDispatch()
    {
        $flashMessenger = $this->_helper->FlashMessenger; // IT IS NULL
    }
}

5条回答
我想做一个坏孩纸
2楼-- · 2019-02-05 19:21

You can also use getActionController to get a reference back to the actioncontroller you were using for any methods you'd normally use there.

查看更多
Viruses.
3楼-- · 2019-02-05 19:25

Another solution is:

$flashMessenger = $this->getActionController()->getHelper('FlashMessenger');
查看更多
萌系小妹纸
4楼-- · 2019-02-05 19:25

You can call it in this way:

$this->_actionController->OtherActionHelper();

The _actionController property references the actual action controller.

查看更多
太酷不给撩
5楼-- · 2019-02-05 19:38

Use the action helper broker:

$flashMessenger =
    Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger');
查看更多
何必那么认真
6楼-- · 2019-02-05 19:38

In addition to mercator's answer, add your method after, see example below:

Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger')->myMethod();
查看更多
登录 后发表回答