Difference between revisions of "Display error messages and notices"
From Joomla! Documentation
m (Added alerts - adds a contextual keyword for a synonym of messages.) |
|||
Line 1: | Line 1: | ||
<noinclude><languages /></noinclude> | <noinclude><languages /></noinclude> | ||
<translate><!--T:1--> | <translate><!--T:1--> | ||
− | Errors, warnings and notices can be displayed from any component, module, plugin or template using the methods outlined below.</translate> | + | Errors, warnings, alerts and notices can be displayed from any component, module, plugin or template using the methods outlined below.</translate> |
<source lang="php"> | <source lang="php"> |
Revision as of 03:55, 26 November 2021
Errors, warnings, alerts 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
$application = JFactory::getApplication();
// Add a message to the message queue
$application->enqueueMessage(JText::_('SOME_ERROR_OCCURRED'), 'error');
/** Alternatively you may use chaining */
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
JFactory::getApplication()->enqueueMessage('Message');
Notice[edit]
Notice
JError::raiseNotice( 100, 'Notice' );
Warning[edit]
Warning
JError::raiseWarning( 100, 'Warning' );
Error[edit]
Error
JError::raiseError( 4711, 'A severe error occurred' );
Joomla! 3.x is bootstrapped[edit]
Since Joomla! uses bootstraped templates, the messages will use the standard bootstrap CSS styles for Alerts.
See: http://getbootstrap.com/2.3.2/components.html#alerts
The general syntax remains:
JFactory::getApplication()->enqueueMessage('Your Message', 'type');
Where type can be one of
- 'message' (or empty) - green
- 'notice' - blue
- 'warning' - yellow
- 'error' - red