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):  
 
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):  
 
+
<source lang="php">
 
//Get a handle to the Joomla!-application object
 
//Get a handle to the Joomla!-application object
 
$app =& JFactory::getApplication();  
 
$app =& JFactory::getApplication();  
 
//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');
 +
</source>
  
 
The second argument to the enqueueMessage()-function is the type of message. Default is 'message', but both error, and I believe also 'warning' will work. The api for the JApplication-object can be found at:  
 
The second argument to the enqueueMessage()-function is the type of message. Default is 'message', but both error, and I believe also 'warning' will work. The api for the JApplication-object can be found at:  
[[http://api.joomla.org/Joomla-Framework/Application/JApplication.html JApplication API]]
+
[http://api.joomla.org/Joomla-Framework/Application/JApplication.html 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:  
 
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:  
 
+
<source lang="php">
 
<jdoc:include type="message" />
 
<jdoc:include type="message" />
 +
</source>

Revision as of 14:51, 24 October 2009

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):

//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');

The second argument to the enqueueMessage()-function is the type of message. Default is 'message', but both error, and I believe also 'warning' will work. 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" />