Joomla getBuffer tutorial

Joomla is something i like and don’t like for various reason but nevertheless i would like to guide you over a very useful feature joomla provides when you have your own modules/components doing some functionality in addition to joomla.

Say, you are using custom library which provides data or stores data and performs various operations in backend. Now say you have encountered some random error or perhaps an information that you would like your beloved user to know about or as feedback from system (well specified in Human-Computer Interaction guidelines).

Lets assume you have a function that saves some information in your own custom DB(not joomla DB) and you want user to know on next page that information was saved successfully.

public function letssave($yourparams="default value"){
//lets get the global app object 
global $mainframe;

//lets call random hypothetical functions
$this->_processUserInput(JRequest::getVar('user_info'));
   if($this->_inputProcessed()=='SUCCESS'){
       $mainframe->enqueueMessage("User your input has been processed successfully");
       $this->_nextProcessing();
       //return to next page
       $mainframe->redirect($return);
   }
   else {
       $mainframe->enqueueMessage("User your input has Failed for unknown reason");
       $this->_failSafeProcessing();
       //return to next/previous page
       $mainframe->redirect($return);
   }

}

Now you have all the code you need to enqueue your feedback messages using mainframe/Application object

Here’s how you can easily retrieve on your pages.

$doc =& JFactory::getDocument();
$buffer = $doc->getBuffer('message');
if($buffer){
  // put some HTML code in here
?>
?

Thats it. Now your users are well informed and upto date and there are no communication gaps between functionality and system feedback

Let me know how it goes for you….