Display error messages and notices

From Joomla! Documentation

Revision as of 11:37, 3 November 2009 by Elkuku (talk | contribs)

Errors, warnings and notices can be displayed from any component, module, plugin or template using the methods outlined below.

//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');

/** PHP 5 */
JFactory::getApplication()->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" />

Message[edit]

Message

/** PHP 4 */
$app = JFactory::getApplication()
$app->enqueueMessage('Message');

/** PHP 5 */
JFactory::getApplication()->enqueueMessage('Message');

Notice[edit]

Notice

JError::raiseNotice(100, 'Notice');

Warning[edit]

Warning

JError::raiseWarning(100, 'Warning');

Error[edit]

JError::raiseError(4711, 'A severe error occured');

See also[edit]