Display error messages and notices

From Joomla! Documentation

Revision as of 14:49, 24 October 2009 by Jonasfh (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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 both error, and I believe also 'warning' will work. The api for the JApplication-object can be found at: [[1]] 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" />