Difference between revisions of "Display error messages and notices"

From Joomla! Documentation

m (added missing ';' to PHP4 enqueueMessage example)
Line 22: Line 22:
 
<source lang="php">
 
<source lang="php">
 
/** PHP 4 */
 
/** PHP 4 */
$app = JFactory::getApplication()
+
$app = JFactory::getApplication();
 
$app->enqueueMessage( 'Message' );
 
$app->enqueueMessage( 'Message' );
  

Revision as of 10:53, 20 July 2011

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]