Actions

Difference between revisions of "Display error messages and notices"

From Joomla! Documentation

m (added missing ';' to PHP4 enqueueMessage example)
(See also)
Line 55: Line 55:
 
* [[JError]]
 
* [[JError]]
 
* [[JApplication]]
 
* [[JApplication]]
*  [http://api.joomla.org/Joomla-Framework/Application/JApplication.html JApplication on api.joomla.org]
+
*  [http://api.joomla.org/1.5/Joomla-Framework/Application/JApplication.html JApplication on api.joomla.org]
  
 
<noinclude>[[Category:Development]]</noinclude>
 
<noinclude>[[Category:Development]]</noinclude>
 
[[Category:Tutorials]][[Category:Component Development]]
 
[[Category:Tutorials]][[Category:Component Development]]

Revision as of 08:55, 29 February 2012

Contents

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

Message

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

Notice

Notice

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

Warning

Warning

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

Error

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

See also