0

I am trying to call a view of helper from a plug in(registered in bootstrap). From any controller i am able to access without any issue but not from a plugin. Below is my code. Any help is appreciated. thank you. Miguel

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

I am getting the following error. Fatal error: Uncaught exception 'Zend_Loader_PluginLoader_Exception' with message 'Plugin by name 'FlashMessages' was not found in the registry; used paths: Zend_Controller_Action_Helper_: Zend/Controller/Action/Helper/' in /usr/local/zend/share/ZendFramework/library/Zend/Loader/PluginLoader.php:412 Stack trace: #0 /usr/local/zend/share/ZendFramework/library/Zend/Controller/Action/HelperBroker.php(366):

Charles
  • 50,943
  • 13
  • 104
  • 142
zeid10
  • 511
  • 8
  • 28

1 Answers1

1

You have to change

Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessages');

to

Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger');

Example:

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

Hope this helps you. Not tested

rkj
  • 8,067
  • 2
  • 27
  • 33
  • FlashMessenger is not the name of my helper the name is FlashMessages and within that class i call: Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger'); – zeid10 May 18 '13 at 05:04
  • Then you need to register your helper FlashMessages in application bootstrap before Plugins_security register. So that it can be available. – rkj May 18 '13 at 05:50
  • how do you register a view helper.I am able to to acccess this helper throughout the application but not within plugin class. – zeid10 May 18 '13 at 19:49
  • First FlashMessenger is not a view helper it is an action helper. we register plugin like this protected function _initPlugins() { //YOUR ACTION HELPER SHOULD BE REGISTER HERE BEFORE $front = Zend_Controller_Front::getInstance(); $front->registerPlugin(new Custom_Plugin_PluginName()); } – rkj May 20 '13 at 02:27