Display error messages and notices
From Joomla! Documentation
(Difference between revisions)
(→See also) |
(Additions for J! 3.x, remove refs to PHP 4) |
||
| Line 2: | Line 2: | ||
Errors, warnings and notices can be displayed from any component, module, plugin or template using the methods outlined below. | Errors, warnings and notices can be displayed from any component, module, plugin or template using the methods outlined below. | ||
<source lang="php"> | <source lang="php"> | ||
| − | //Get a handle to the Joomla! application object | + | // Get a handle to the Joomla! application object |
| − | $ | + | $application = JFactory::getApplication(); |
| − | + | ||
| − | + | ||
| − | /** Alternatively | + | // Add a message to the message queue |
| − | JFactory::getApplication()->enqueueMessage( JText::_( ' | + | $application->enqueueMessage(JText::_('SOME_ERROR_OCCURED'), 'error'); |
| + | |||
| + | /** Alternatively you may use chaining */ | ||
| + | JFactory::getApplication()->enqueueMessage(JText::_('SOME_ERROR_OCCURED'), 'error'); | ||
</source> | </source> | ||
| Line 21: | Line 22: | ||
</div> | </div> | ||
<source lang="php"> | <source lang="php"> | ||
| − | + | JFactory::getApplication()->enqueueMessage('Message'); | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | JFactory::getApplication()->enqueueMessage( 'Message' ); | + | |
</source> | </source> | ||
| Line 51: | Line 47: | ||
JError::raiseError( 4711, 'A severe error occurred' ); | JError::raiseError( 4711, 'A severe error occurred' ); | ||
</source> | </source> | ||
| + | |||
| + | == Joomla! 3.x and the Bootstrap template == | ||
| + | Since Joomla! {{JVer|3.0}} will use the bootstrap template, the messages will use the standard boostrap css styles for Alerts. | ||
| + | |||
| + | See: http://twitter.github.com/bootstrap/components.html#alerts | ||
| + | |||
| + | The general syntax remains: | ||
| + | |||
| + | <source lang="php"> | ||
| + | JFactory::getApplication()->enqueueMessage('Your Message', 'type); | ||
| + | </source> | ||
| + | |||
| + | Where '''type''' can be one of | ||
| + | |||
| + | * EMPTY - yellow | ||
| + | * 'info' - blue | ||
| + | * 'error' - red | ||
| + | * 'success' - green | ||
== See also == | == See also == | ||
Revision as of 02:49, 12 September 2012
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_OCCURED'), 'error'); /** Alternatively you may use chaining */ JFactory::getApplication()->enqueueMessage(JText::_('SOME_ERROR_OCCURED'), '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 and the Bootstrap template
Since Joomla!
will use the bootstrap template, 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