在前端控制器插件中访问action-helper

时间:2013-05-18 03:35:16

标签: zend-framework helper front-controller

我试图从插件中调用helper视图(在bootstrap中注册)。从任何控制器我能够访问没有任何问题,但不是从插件。以下是我的代码。任何帮助表示赞赏。 谢谢。米格尔

class Plugins_security extends Zend_Controller_Plugin_Abstract
{
    public function preDispatch (Zend_Controller_Request_Abstract $request)
    {
        $auth = Zend_Auth::getInstance();
        $moduleName = $request->getModuleName();
        if ($request->getModuleName() != "auth") 
        {
            $auth = Zend_Auth::getInstance();
            if (! $auth->hasIdentity()) 
            {
                $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper(
                'redirector');
                $flashMessenger = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessages');
                $flashMessenger->flashMessenger (array('message' => 'Sessao expirada', 'status' => 'error'));
                $redirector->gotoUrl('/auth/login/')->redirectAndExit();
            }
        }
    }
} 

我收到以下错误。 致命错误:在注册表中找不到未捕获的异常'Zend_Loader_PluginLoader_Exception',消息'按名称插入'FlashMessages';使用的路径:Zend_Controller_Action_Helper_:Zend / Controller / Action / Helper /'在/usr/local/zend/share/ZendFramework/library/Zend/Loader/PluginLoader.php:412堆栈跟踪:#0 / usr / local / zend / share /ZendFramework/library/Zend/Controller/Action/HelperBroker.php(366):

1 个答案:

答案 0 :(得分:1)

你必须改变

Zend_Controller_Action_HelperBroker :: getStaticHelper('FlashMessages');

<强> Zend_Controller_Action_HelperBroker :: getStaticHelper( 'FlashMessenger');

示例:

$ flashMessenger = Zend_Controller_Action_HelperBroker :: getStaticHelper('FlashMessenger'); $ flashMessenger-&gt; addMessage(array('error'=&gt;'Session expired'));

希望这会对你有所帮助。未经测试