Display error messages and notices
From Joomla! Documentation
Revision as of 14:39, 3 November 2009 by Chris Davenport (talk | contribs) (Tidied up a little. Added categorisation.)
Revision as of 14:39, 3 November 2009 by Chris Davenport (talk | contribs) (Tidied up a little. Added categorisation.)
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::_( 'Some error occurred' ), 'error' );
/** Alternatively, in PHP 5 */
JFactory::getApplication()->enqueueMessage( JText::_( 'Some error occurred' ), 'error' );
The second argument to the enqueueMessage function is the type of the message. The default is 'message', but 'error' results in a different style for the message. The message will be displayed in place of a special jdoc:include statement in your template. Place the following in your template at the location where you want messages to appear.
<jdoc:include type="message" />
Message[edit]
Message
/** PHP 4 */
$app = JFactory::getApplication()
$app->enqueueMessage( 'Message' );
/** Alternatively, in 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 occurred' );