I want to extend Zend_Controller_Action so I can have messaging be universal. Right now in the preDispatch() I am setting all the error and warning messages. How can I make the AddMessage (see code) and preDispatch functions be universal throughout all controllers?
<?php
class PlaygroundController extends Zend_Controller_Action {
public function init()
{
/* Initialize action controller here */
}
public function preDispatch()
{
$flashMessenger = $this->_helper->FlashMessenger;
$flashMessenger->setNamespace('Errors');
$this->view->Errors = $flashMessenger->getMessages();
$flashMessenger->setNamespace('Warnings');
$this->view->Warnings = $flashMessenger->getMessages();
$flashMessenger->setNamespace('Messages');
$this->view->Messages = $flashMessenger->getMessages();
$flashMessenger->setNamespace('Success');
$this->view->Success = $flashMessenger->getMessages();
}
protected function AddMessage($message,$type='Errors') {
$flashMessenger = $this->_helper->FlashMessenger;
$flashMessenger->setNamespace($type);
$flashMessenger->addMessage($message);
}
public function flashAction()
{
$this->AddMessage('This is an error message');
$this->AddMessage('This is another error message');
$this->AddMessage('This is a warning message','Warnings');
$this->AddMessage('This is message','Messages');
$this->AddMessage('This is another success message','Success');
}
}