Actions

Difference between revisions of "Display error messages and notices"

From Joomla! Documentation

(Add "Success")
(Make success subset of Joomla 3.0)
(3 intermediate revisions by 2 users not shown)
Line 6: Line 6:
  
 
// Add a message to the message queue
 
// Add a message to the message queue
$application->enqueueMessage(JText::_('SOME_ERROR_OCCURED'), 'error');
+
$application->enqueueMessage(JText::_('SOME_ERROR_OCCURRED'), 'error');
  
 
/** Alternatively you may use chaining */
 
/** Alternatively you may use chaining */
JFactory::getApplication()->enqueueMessage(JText::_('SOME_ERROR_OCCURED'), 'error');
+
JFactory::getApplication()->enqueueMessage(JText::_('SOME_ERROR_OCCURRED'), 'error');
 
</source>
 
</source>
  
Line 56: Line 56:
  
 
<source lang="php">
 
<source lang="php">
JFactory::getApplication()->enqueueMessage('Your Message', 'type);
+
JFactory::getApplication()->enqueueMessage('Your Message', 'type');
 
</source>
 
</source>
  
Line 66: Line 66:
 
* 'success' - green
 
* 'success' - green
  
== Success ==
+
=== Success ===
Note the new style in Joomla! 3 using the type '''success'''
+
Note the new style in Joomla! 3 using the type '''success''' which is now used instead of the former "Message".
  
 
<div style="background-color: #dff0d8; color: #468847; border-top: 3px solid #468847; border-bottom: 3px solid #468847; padding-left: 1em; font-weight: bold;">
 
<div style="background-color: #dff0d8; color: #468847; border-top: 3px solid #468847; border-bottom: 3px solid #468847; padding-left: 1em; font-weight: bold;">
Line 74: Line 74:
  
 
<source lang="php">
 
<source lang="php">
JFactory::getApplication()->enqueueMessage('Success', 'success');
+
JFactory::getApplication()->enqueueMessage('Success');
 
</source>
 
</source>
  

Revision as of 08:34, 4 February 2013

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
$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

Message

JFactory::getApplication()->enqueueMessage('Message');

Notice

Notice

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

Warning

Warning

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

Error

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

Joomla! 3.x is bootstraped

Since Joomla! Joomla 3.0 will use bootstraped templates, the messages will use the standard boostrap CSS styles for Alerts.

See: http://twitter.github.com/bootstrap/components.html#alerts

The general syntax remains:

JFactory::getApplication()->enqueueMessage('Your Message', 'type');

Where type can be one of

  • EMPTY - yellow
  • 'info' - blue
  • 'error' - red
  • 'success' - green

Success

Note the new style in Joomla! 3 using the type success which is now used instead of the former "Message".

Success

JFactory::getApplication()->enqueueMessage('Success');

See also