Zend的框架,从另一个动作助手中调用一个动作助手(zend-framework, call an

2019-06-25 17:15发布

我写一个动作助手,我需要从助手里调用另一个动作助手。 但我不知道怎么办。 在这里的示例代码:

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
    }
}

Answer 1:

使用动作助手经纪人 :

$flashMessenger =
    Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger');


Answer 2:

另一种解决方案是:

$flashMessenger = $this->getActionController()->getHelper('FlashMessenger');


Answer 3:

您还可以使用getActionController得到一个参考回到你使用你通常会使用有什么方法ActionController的。



Answer 4:

除了墨卡托的答案,之后添加你的方法,请参见下面例子:

Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger')->myMethod();


Answer 5:

你可以把它用这种方式:

$this->_actionController->OtherActionHelper();

_actionController属性引用的实际动作控制器。



文章来源: zend-framework, call an action helper from within another action helper