Compago

...free knowledge

 
  • Increase font size
  • Default font size
  • Decrease font size
Home Manuali Programmazione How to create and delete message in Joomla

How to create and delete message in Joomla

E-mail Stampa PDF

In Joomla it's be very usefull to show some message for the user using the application framework, to do this is enought to have the access to the application object:

JFactory::getApplication()->enqueueMessage('text to show','message');

where the secon parameter could be "message" or "notice" or "error". 
Untill now is quite easy but the application don't let the programmers delete the message already enqueued. Here is how to create and delete message in Joomla, using the message queue:

function addMsg() { 
 $app=JFactory::getApplication();
 //optional check if the queue is empty 
 $q=$app->getMessageQueue(); 
 if (count($q)==0){ 
   //add message
   $app->enqueueMessage('ACmsg','message'); 
 }
} 
 
function delMsg() { 
 $app=JFactory::getApplication(); 
 $appReflection = new ReflectionClass(get_class($app)); 
 $_messageQueue = $appReflection->getProperty('_messageQueue'); 
 $_messageQueue->setAccessible(true); 
 $messages = $_messageQueue->getValue($app); 
 foreach($messages as $key=>$message) { 
   if($message['message'] == 'ACmsg') {
     //delete message
     unset($messages[$key]); 
   } 
 } 
 $_messageQueue->setValue($app,$messages); 
}

The reflection class is used to get information and modify the messageQueue of the application.

 
Loading

Login