Display error messages and notices
From Joomla! Documentation
(Difference between revisions)
Phproberto (Talk | contribs) m (Fix missin quote) |
(Update 3.0 to 3.x) |
||
| (2 intermediate revisions by 2 users not shown) | |||
| Line 49: | Line 49: | ||
== Joomla! 3.x is bootstraped == | == Joomla! 3.x is bootstraped == | ||
| − | Since Joomla! {{JVer|3. | + | Since Joomla! {{JVer|3.x}} uses bootstraped templates, the messages will use the standard bootstrap CSS styles for Alerts. |
See: http://twitter.github.com/bootstrap/components.html#alerts | See: http://twitter.github.com/bootstrap/components.html#alerts | ||
| Line 61: | Line 61: | ||
Where '''type''' can be one of | Where '''type''' can be one of | ||
| − | * | + | * 'warning' - yellow |
| − | * ' | + | * 'notice' - blue |
* 'error' - red | * 'error' - red | ||
| − | * ' | + | * 'message' (or empty) - green |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
== See also == | == See also == | ||
Latest revision as of 04:34, 29 April 2013
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" />
[edit] Message
Message
JFactory::getApplication()->enqueueMessage('Message');
[edit] Notice
Notice
JError::raiseNotice( 100, 'Notice' );
[edit] Warning
Warning
JError::raiseWarning( 100, 'Warning' );
[edit] Error
JError::raiseError( 4711, 'A severe error occurred' );
[edit] Joomla! 3.x is bootstraped
Since Joomla!
uses bootstraped templates, the messages will use the standard bootstrap 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
- 'warning' - yellow
- 'notice' - blue
- 'error' - red
- 'message' (or empty) - green