Display error messages and notices
From Joomla! Documentation
(Difference between revisions)
m (Tidied up a little. Added categorisation.) |
|||
| Line 58: | Line 58: | ||
<noinclude>[[Category:Development]]</noinclude> | <noinclude>[[Category:Development]]</noinclude> | ||
| + | [[Category:Tutorials]][[Category:Component Development]] | ||
Revision as of 08:16, 20 September 2010
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' );