Display error messages and notices

From Joomla! Documentation

Revision as of 10:53, 20 July 2011 by Kyrotomia (talk | contribs) (added missing ';' to PHP4 enqueueMessage example)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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

See also[edit]