Actions

Difference between revisions of "Display error messages and notices"

From Joomla! Documentation

Line 7: Line 7:
 
</source>
 
</source>
  
The second argument to the enqueueMessage()-function is the type of message. Default is 'message', but both error, and I believe also 'warning' will work. The api for the JApplication-object can be found at:  
+
The second argument to the enqueueMessage()-function is the type of message. Default is 'message', but 'error' gives a different style message. Try other types as well, to see how that works. The api for the JApplication-object can be found at:  
 
[http://api.joomla.org/Joomla-Framework/Application/JApplication.html JApplication API]
 
[http://api.joomla.org/Joomla-Framework/Application/JApplication.html JApplication API]
 
The error message will now be displayed if the message-tag is present in your template. The message-field is added with the following statement in your template:  
 
The error message will now be displayed if the message-tag is present in your template. The message-field is added with the following statement in your template:  

Revision as of 13:57, 24 October 2009

Errors, warnings and notices can be displayed from any component, module, plugin or template using the method outlined below (took me some time to figure this out, might help someone else):

//Get a handle to the Joomla!-application object
$app =& JFactory::getApplication(); 
//add a message to the message queue
$app->enqueueMessage(JText::_('Random error occured'), 'error');

The second argument to the enqueueMessage()-function is the type of message. Default is 'message', but 'error' gives a different style message. Try other types as well, to see how that works. The api for the JApplication-object can be found at: JApplication API The error message will now be displayed if the message-tag is present in your template. The message-field is added with the following statement in your template:

<jdoc:include type="message" />