Actions

Difference between revisions of "Display error messages and notices"

From Joomla! Documentation

Line 1: Line 1:
Errors, warnings and notices can be displayed from any component, module, plugin or template using the method outlined below (took me some time to figure this out, might help someone else):
+
{{RightTOC}}
 +
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
Line 5: Line 6:
 
//add a message to the message queue
 
//add a message to the message queue
 
$app->enqueueMessage(JText::_('Random error occured'), 'error');
 
$app->enqueueMessage(JText::_('Random error occured'), 'error');
 +
 +
/** PHP 5 */
 +
JFactory::getApplication()->enqueueMessage(JText::_('Random error occured'), 'error');
 
</source>
 
</source>
  
Line 13: Line 17:
 
<jdoc:include type="message" />
 
<jdoc:include type="message" />
 
</source>
 
</source>
 +
 +
== Message ==
 +
<div style="background-color: #c3d2e5; color: #0055bb; border-top: 3px solid #84a7db; border-bottom: 3px solid #84a7db; padding-left: 1em; font-weight: bold;">
 +
Message
 +
</div>
 +
<source lang="php">
 +
/** PHP 4 */
 +
$app = JFactory::getApplication()
 +
$app->enqueueMessage('Message');
 +
 +
/** PHP 5 */
 +
JFactory::getApplication()->enqueueMessage('Message');
 +
 +
</source>
 +
 +
== Notice ==
 +
 +
<div style="background-color: #efe7b8; color: #c00; border-top: 3px solid #f0dc7e; border-bottom: 3px solid #f0dc7e; padding-left: 1em; font-weight: bold;">
 +
Notice
 +
</div>
 +
<source lang="php">
 +
JError::raiseNotice(100, 'Notice');
 +
</source>
 +
 +
== Warning ==
 +
 +
<div style="background-color: #e6c0c0; color: #c00; border-top: 3px solid #DE7A7B; border-bottom: 3px solid #DE7A7B; padding-left: 1em; font-weight: bold;">
 +
Warning
 +
</div>
 +
<source lang="php">
 +
JError::raiseWarning(100, 'Warning');
 +
</source>
 +
 +
== Error ==
 +
<source lang="php">
 +
JError::raiseError(4711, 'A severe error occured');
 +
</source>
 +
 +
== See also ==
 +
* [[JError]]

Revision as of 11:37, 3 November 2009

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::_('Random error occured'), 'error');
 
/** PHP 5 */
JFactory::getApplication()->enqueueMessage(JText::_('Random error occured'), 'error');

The second argument to the enqueueMessage()-function is the type of message. Default is 'message', but 'error' gives a different style message. Try other types as well, to see how that works. The api for the JApplication-object can be found at: JApplication API The error message will now be displayed if the message-tag is present in your template. The message-field is added with the following statement in your template:

<jdoc:include type="message" />

Message

Message

/** PHP 4 */
$app = JFactory::getApplication()
$app->enqueueMessage('Message');
 
/** 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 occured');

See also