0

我正在尝试从插件(在引导程序中注册)调用助手视图。从任何控制器我都可以毫无问题地访问,但不能从插件访问。下面是我的代码。任何帮助表示赞赏。谢谢你。米格尔

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();
            }
        }
    }
} 

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

4

1 回答 1

1

你必须改变

Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessages');

Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger');

例子:

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

希望这对您有所帮助。未测试

于 2013-05-18T04:22:10.650 回答