I need the same 2 lines in all my controllers, each controller has its own initialization logic, but these two lines are common to all of them.
public function init()
{
$fm =$this->_helper->getHelper('FlashMessenger');
$this->view->messages = $fm->getMessages();
}
How can I avoid code repetition?
Update:
Well, FlashMessenger was just an example, let's say I need to write a log line in every action, except for 'someAction' @ 'someController'. So, new common lines should be.
$this->logger = new Zend_Log();
$writer = new Zend_Log_Writer_Stream(APPLICATION_PATH.'/../logs/log.txt');
$this->logger->addWriter($writer);
$this->logger->log('Some Message',Zend_Log::DEBUG);
, , init() .
?. : "someAction".
"BaseController" . : ? ( : Class 'BaseController' ).