Difference between revisions of "Display error messages and notices"

From Joomla! Documentation

(Marked for translation)
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
<noinclude><languages /></noinclude>
 
<noinclude><languages /></noinclude>
<translate>Errors, warnings and notices can be displayed from any component, module, plugin or template using the methods outlined below.</translate>
+
<translate><!--T:1-->
 +
Errors, warnings and notices can be displayed from any component, module, plugin or template using the methods outlined below.</translate>
  
 
<source lang="php">
 
<source lang="php">
Line 13: Line 14:
 
</source>
 
</source>
  
<translate>The second argument to the [http://api.joomla.org/11.4/Joomla-Platform/Application/JApplication.html#enqueueMessage 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 <tt>jdoc:include</tt> statement in your template.  Place the following in your template at the location where you want messages to appear.</translate>
+
<translate><!--T:2-->
 +
The second argument to the [http://api.joomla.org/11.4/Joomla-Platform/Application/JApplication.html#enqueueMessage 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 <tt>jdoc:include</tt> statement in your template.  Place the following in your template at the location where you want messages to appear.</translate>
  
 
<source lang="php">
 
<source lang="php">
Line 20: Line 22:
  
 
<translate>
 
<translate>
== Message ==
+
== Message == <!--T:3-->
 
</translate>
 
</translate>
  
<div style="background-color: #c3d2e5; color: #0055bb; border-top: 3px solid #84a7db; border-bottom: 3px solid #84a7db; padding-left: 1em; font-weight: bold;">
+
<div style="background-color: #dff0d8; color: #3c763d; border-top: 3px solid #d6e9c6; border-bottom: 3px solid #d6e9c6; padding-left: 1em; font-weight: bold;">
 
Message
 
Message
 
</div>
 
</div>
Line 31: Line 33:
  
 
<translate>
 
<translate>
== Notice ==
+
== Notice == <!--T:4-->
 
</translate>
 
</translate>
  
<div style="background-color: #efe7b8; color: #c00; border-top: 3px solid #f0dc7e; border-bottom: 3px solid #f0dc7e; padding-left: 1em; font-weight: bold;">
+
<div style="background-color: #c3d2e5; color: #0055bb; border-top: 3px solid #84a7db; border-bottom: 3px solid #84a7db; padding-left: 1em; font-weight: bold;">
 
Notice
 
Notice
 
</div>
 
</div>
Line 42: Line 44:
  
 
<translate>
 
<translate>
== Warning ==
+
== Warning == <!--T:5-->
 
</translate>
 
</translate>
  
<div style="background-color: #e6c0c0; color: #c00; border-top: 3px solid #DE7A7B; border-bottom: 3px solid #DE7A7B; padding-left: 1em; font-weight: bold;">
+
<div style="background-color: #efe7b8; color: #c00; border-top: 3px solid #f0dc7e; border-bottom: 3px solid #f0dc7e; padding-left: 1em; font-weight: bold;">
 
Warning
 
Warning
 
</div>
 
</div>
Line 53: Line 55:
  
 
<translate>
 
<translate>
== Error ==
+
== Error == <!--T:6-->
 
</translate>
 
</translate>
  
 +
<div style="background-color: #e6c0c0; color: #c00; border-top: 3px solid #DE7A7B; border-bottom: 3px solid #DE7A7B; padding-left: 1em; font-weight: bold;">
 +
Error
 +
</div>
 
<source lang="php">
 
<source lang="php">
 
JError::raiseError( 4711, 'A severe error occurred' );
 
JError::raiseError( 4711, 'A severe error occurred' );
Line 61: Line 66:
  
 
<translate>
 
<translate>
== Joomla! 3.x is bootstrapped ==
+
== Joomla! 3.x is bootstrapped == <!--T:7-->
 
</translate>
 
</translate>
<translate>Since Joomla! {{JVer|3.x}} uses bootstraped templates, the messages will use the standard bootstrap CSS styles for Alerts.</translate>
+
<translate><!--T:8-->
 +
Since Joomla! {{JVer|3.x}} uses bootstraped templates, the messages will use the standard bootstrap CSS styles for Alerts.</translate>
  
<translate>See: http://getbootstrap.com/2.3.2/components.html#alerts</translate>
+
<translate><!--T:9-->
 +
See: http://getbootstrap.com/2.3.2/components.html#alerts</translate>
  
<translate>The general syntax remains:</translate>
+
<translate><!--T:10-->
 +
The general syntax remains:</translate>
  
 
<source lang="php">
 
<source lang="php">
Line 73: Line 81:
 
</source>
 
</source>
  
<translate>Where '''type''' can be one of</translate>
+
<translate><!--T:11-->
 +
Where '''type''' can be one of</translate>
  
<translate>* 'warning' - yellow
+
<translate><!--T:12-->
 +
* 'message' (or empty) - green
 
* 'notice' - blue
 
* 'notice' - blue
 +
* 'warning' - yellow
 
* 'error' - red
 
* 'error' - red
* 'message' (or empty) - green</translate>
+
</translate>
  
 
<translate>
 
<translate>
== See also ==
+
== See also == <!--T:13-->
 
</translate>
 
</translate>
<translate>* [http://api.joomla.org/11.4/Joomla-Platform/Error/JError.html JError on api.joomla.org]
+
<translate><!--T:14-->
 +
* [http://api.joomla.org/11.4/Joomla-Platform/Error/JError.html JError on api.joomla.org]
 
* [http://api.joomla.org/11.4/Joomla-Platform/Application/JApplication.html JApplication on api.joomla.org]
 
* [http://api.joomla.org/11.4/Joomla-Platform/Application/JApplication.html JApplication on api.joomla.org]
 
</translate>
 
</translate>
 
+
__NOTOC__
 
<noinclude>
 
<noinclude>
 
<translate>
 
<translate>
 +
<!--T:15-->
 
[[Category:Development]]
 
[[Category:Development]]
 
[[Category:Tutorials]]
 
[[Category:Tutorials]]

Revision as of 13:13, 27 October 2015

Other languages:
Deutsch • ‎English • ‎Nederlands • ‎español • ‎français

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[edit]

Message

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

Notice[edit]

Notice

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

Warning[edit]

Warning

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

Error[edit]

Error

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

Joomla! 3.x is bootstrapped[edit]

Since Joomla! Joomla 3.x uses bootstraped templates, the messages will use the standard bootstrap CSS styles for Alerts.

See: http://getbootstrap.com/2.3.2/components.html#alerts

The general syntax remains:

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

Where type can be one of

  • 'message' (or empty) - green
  • 'notice' - blue
  • 'warning' - yellow
  • 'error' - red

See also[edit]