<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://docs.sandbox.joomla.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jumpy972</id>
	<title>Joomla! Documentation - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://docs.sandbox.joomla.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jumpy972"/>
	<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/Special:Contributions/Jumpy972"/>
	<updated>2026-09-11T08:23:12Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.0</generator>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Sending_email_from_extensions&amp;diff=65245</id>
		<title>Sending email from extensions</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Sending_email_from_extensions&amp;diff=65245"/>
		<updated>2012-02-29T13:56:38Z</updated>

		<summary type="html">&lt;p&gt;Jumpy972: /* See also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is an example of how to send an email from a component. You would typically put this into your components controller.&lt;br /&gt;
&lt;br /&gt;
=== Fetch the mail object ===&lt;br /&gt;
A reference to the global mail object (JMail) is fetched through the JFactory object. This is the object creating our mail.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$mailer =&amp;amp; JFactory::getMailer();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Set a sender ===&lt;br /&gt;
The sender of an email is set with [http://api.joomla.org/Joomla-Framework/Mail/JMail.html#setSender setSender]. The function takes an array with an email address and a name as an argument. We fetch the sites email address and name from the global configuration. These are set in the administration back-end (Global Configuration -&amp;gt; Server -&amp;gt; Mail Settings).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$config =&amp;amp; JFactory::getConfig();&lt;br /&gt;
$sender = array( &lt;br /&gt;
    $config-&amp;gt;getValue( &#039;config.mailfrom&#039; ),&lt;br /&gt;
    $config-&amp;gt;getValue( &#039;config.fromname&#039; ) );&lt;br /&gt;
&lt;br /&gt;
$mailer-&amp;gt;setSender($sender);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recipient ===&lt;br /&gt;
You set the recipient of an email with the function [http://api.joomla.org/1.5/Joomla-Framework/Mail/JMail.html# addRecipient].&lt;br /&gt;
To set the email address to the currently logged in user, we fetch it from the user object.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$user =&amp;amp; JFactory::getUser();&lt;br /&gt;
$recipient = $user-&amp;gt;email;&lt;br /&gt;
&lt;br /&gt;
$mailer-&amp;gt;addRecipient($recipient);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we had multiple recipients we would put each recipients email address in an array.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$recipient = array( &#039;person1@domain.com&#039;, &#039;person2@domain.com&#039;, &#039;person3@domain.com&#039; );&lt;br /&gt;
&lt;br /&gt;
$mailer-&amp;gt;addRecipient($recipient);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Create the mail ===&lt;br /&gt;
We need to set a subject line and create the text body. The subject is set with [http://api.joomla.org/Joomla-Framework/Mail/JMail.html#setSubject setSubject]. &lt;br /&gt;
&lt;br /&gt;
The easy way to create an email body is as a string with plain text. Use the  function [http://api.joomla.org/Joomla-Framework/Mail/JMail.html#setBody setBody] to add a message to the mail body. You can also attach a file with [http://api.joomla.org/Joomla-Framework/Mail/JMail.html#addAttachment addAttachment]. It takes a single file name or an array of file names as argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$body   = &amp;quot;Your body string\nin double quotes if you want to parse the \nnewlines etc&amp;quot;;&lt;br /&gt;
$mailer-&amp;gt;setSubject(&#039;Your subject string&#039;);&lt;br /&gt;
$mailer-&amp;gt;setBody($body);&lt;br /&gt;
// Optional file attached&lt;br /&gt;
$mailer-&amp;gt;addAttachment(JPATH_COMPONENT.DS.&#039;assets&#039;.DS.&#039;document.pdf&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you prefer to format your email in HTML, you need to tell the mailer it is HTML. This is done with [http://api.joomla.org/Unknown/PHPMailer.html#methodIsHTML IsHTML]. When sending HTML emails you should normally set the [http://api.joomla.org/Unknown/PHPMailer.html#$Encoding Encoding] to base64 in order to avoid unwanted characters in the output. The subject line and any attachments are handled as above, with the exception of images embedded in the HTML. These are taken care of with the function [http://api.joomla.org/Unknown/PHPMailer.html#AddEmbeddedImage AddEmbeddedImage].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$body   = &#039;&amp;lt;h2&amp;gt;Our mail&amp;lt;/h2&amp;gt;&#039;&lt;br /&gt;
    . &#039;&amp;lt;div&amp;gt;A message to our dear readers&#039;&lt;br /&gt;
    . &#039;&amp;lt;img src=&amp;quot;cid:logo_id&amp;quot; alt=&amp;quot;logo&amp;quot;/&amp;gt;&amp;lt;/div&amp;gt;&#039;;&lt;br /&gt;
$mailer-&amp;gt;isHTML(true);&lt;br /&gt;
$mailer-&amp;gt;Encoding = &#039;base64&#039;;&lt;br /&gt;
$mailer-&amp;gt;setBody($body);&lt;br /&gt;
// Optionally add embedded image&lt;br /&gt;
$mailer-&amp;gt;AddEmbeddedImage( JPATH_COMPONENT.DS.&#039;assets&#039;.DS.&#039;logo128.jpg&#039;, &#039;logo_id&#039;, &#039;logo.jpg&#039;, &#039;base64&#039;, &#039;image/jpeg&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Normally you would leave any images on your server and refer to them with an ordinary HTML image tag, to reduce size of the mail and the time sending it.&lt;br /&gt;
&lt;br /&gt;
=== Sending the mail ===&lt;br /&gt;
&lt;br /&gt;
The mail is sent with the function [http://api.joomla.org/Joomla-Framework/Mail/JMail.html#Send Send]. It returns &#039;&#039;&#039;true&#039;&#039;&#039; on success or a JError object.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$send =&amp;amp; $mailer-&amp;gt;Send();&lt;br /&gt;
if ( $send !== true ) {&lt;br /&gt;
    echo &#039;Error sending email: &#039; . $send-&amp;gt;message;&lt;br /&gt;
} else {&lt;br /&gt;
    echo &#039;Mail sent&#039;;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You would probably want to write your own error handler, if there is an error sending the mail.&lt;br /&gt;
&lt;br /&gt;
The JMail object is used for sending mail in Joomlas contact manager. See the file joomla/components/com_contact/controller.php&lt;br /&gt;
&lt;br /&gt;
===See also===&lt;br /&gt;
* [http://docs.joomla.org/JFactory/getMailer Docs on JFactory-&amp;gt;getMailer]&lt;br /&gt;
* [http://api.joomla.org/1.5/Joomla-Framework/JFactory.html#getMailer JFactory-&amp;gt;getMailer on api.joomla.org]&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>Jumpy972</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Sending_email_from_extensions&amp;diff=65244</id>
		<title>Sending email from extensions</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Sending_email_from_extensions&amp;diff=65244"/>
		<updated>2012-02-29T13:56:14Z</updated>

		<summary type="html">&lt;p&gt;Jumpy972: /* Recipient */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This is an example of how to send an email from a component. You would typically put this into your components controller.&lt;br /&gt;
&lt;br /&gt;
=== Fetch the mail object ===&lt;br /&gt;
A reference to the global mail object (JMail) is fetched through the JFactory object. This is the object creating our mail.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$mailer =&amp;amp; JFactory::getMailer();&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Set a sender ===&lt;br /&gt;
The sender of an email is set with [http://api.joomla.org/Joomla-Framework/Mail/JMail.html#setSender setSender]. The function takes an array with an email address and a name as an argument. We fetch the sites email address and name from the global configuration. These are set in the administration back-end (Global Configuration -&amp;gt; Server -&amp;gt; Mail Settings).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$config =&amp;amp; JFactory::getConfig();&lt;br /&gt;
$sender = array( &lt;br /&gt;
    $config-&amp;gt;getValue( &#039;config.mailfrom&#039; ),&lt;br /&gt;
    $config-&amp;gt;getValue( &#039;config.fromname&#039; ) );&lt;br /&gt;
&lt;br /&gt;
$mailer-&amp;gt;setSender($sender);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Recipient ===&lt;br /&gt;
You set the recipient of an email with the function [http://api.joomla.org/1.5/Joomla-Framework/Mail/JMail.html# addRecipient].&lt;br /&gt;
To set the email address to the currently logged in user, we fetch it from the user object.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$user =&amp;amp; JFactory::getUser();&lt;br /&gt;
$recipient = $user-&amp;gt;email;&lt;br /&gt;
&lt;br /&gt;
$mailer-&amp;gt;addRecipient($recipient);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we had multiple recipients we would put each recipients email address in an array.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$recipient = array( &#039;person1@domain.com&#039;, &#039;person2@domain.com&#039;, &#039;person3@domain.com&#039; );&lt;br /&gt;
&lt;br /&gt;
$mailer-&amp;gt;addRecipient($recipient);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Create the mail ===&lt;br /&gt;
We need to set a subject line and create the text body. The subject is set with [http://api.joomla.org/Joomla-Framework/Mail/JMail.html#setSubject setSubject]. &lt;br /&gt;
&lt;br /&gt;
The easy way to create an email body is as a string with plain text. Use the  function [http://api.joomla.org/Joomla-Framework/Mail/JMail.html#setBody setBody] to add a message to the mail body. You can also attach a file with [http://api.joomla.org/Joomla-Framework/Mail/JMail.html#addAttachment addAttachment]. It takes a single file name or an array of file names as argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$body   = &amp;quot;Your body string\nin double quotes if you want to parse the \nnewlines etc&amp;quot;;&lt;br /&gt;
$mailer-&amp;gt;setSubject(&#039;Your subject string&#039;);&lt;br /&gt;
$mailer-&amp;gt;setBody($body);&lt;br /&gt;
// Optional file attached&lt;br /&gt;
$mailer-&amp;gt;addAttachment(JPATH_COMPONENT.DS.&#039;assets&#039;.DS.&#039;document.pdf&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you prefer to format your email in HTML, you need to tell the mailer it is HTML. This is done with [http://api.joomla.org/Unknown/PHPMailer.html#methodIsHTML IsHTML]. When sending HTML emails you should normally set the [http://api.joomla.org/Unknown/PHPMailer.html#$Encoding Encoding] to base64 in order to avoid unwanted characters in the output. The subject line and any attachments are handled as above, with the exception of images embedded in the HTML. These are taken care of with the function [http://api.joomla.org/Unknown/PHPMailer.html#AddEmbeddedImage AddEmbeddedImage].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$body   = &#039;&amp;lt;h2&amp;gt;Our mail&amp;lt;/h2&amp;gt;&#039;&lt;br /&gt;
    . &#039;&amp;lt;div&amp;gt;A message to our dear readers&#039;&lt;br /&gt;
    . &#039;&amp;lt;img src=&amp;quot;cid:logo_id&amp;quot; alt=&amp;quot;logo&amp;quot;/&amp;gt;&amp;lt;/div&amp;gt;&#039;;&lt;br /&gt;
$mailer-&amp;gt;isHTML(true);&lt;br /&gt;
$mailer-&amp;gt;Encoding = &#039;base64&#039;;&lt;br /&gt;
$mailer-&amp;gt;setBody($body);&lt;br /&gt;
// Optionally add embedded image&lt;br /&gt;
$mailer-&amp;gt;AddEmbeddedImage( JPATH_COMPONENT.DS.&#039;assets&#039;.DS.&#039;logo128.jpg&#039;, &#039;logo_id&#039;, &#039;logo.jpg&#039;, &#039;base64&#039;, &#039;image/jpeg&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Normally you would leave any images on your server and refer to them with an ordinary HTML image tag, to reduce size of the mail and the time sending it.&lt;br /&gt;
&lt;br /&gt;
=== Sending the mail ===&lt;br /&gt;
&lt;br /&gt;
The mail is sent with the function [http://api.joomla.org/Joomla-Framework/Mail/JMail.html#Send Send]. It returns &#039;&#039;&#039;true&#039;&#039;&#039; on success or a JError object.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$send =&amp;amp; $mailer-&amp;gt;Send();&lt;br /&gt;
if ( $send !== true ) {&lt;br /&gt;
    echo &#039;Error sending email: &#039; . $send-&amp;gt;message;&lt;br /&gt;
} else {&lt;br /&gt;
    echo &#039;Mail sent&#039;;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You would probably want to write your own error handler, if there is an error sending the mail.&lt;br /&gt;
&lt;br /&gt;
The JMail object is used for sending mail in Joomlas contact manager. See the file joomla/components/com_contact/controller.php&lt;br /&gt;
&lt;br /&gt;
===See also===&lt;br /&gt;
* [http://docs.joomla.org/JFactory/getMailer Docs on JFactory-&amp;gt;getMailer]&lt;br /&gt;
* [http://api.joomla.org/Joomla-Framework/JFactory.html#getMailer JFactory-&amp;gt;getMailer on api.joomla.org]&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>Jumpy972</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Display_error_messages_and_notices&amp;diff=65243</id>
		<title>Display error messages and notices</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Display_error_messages_and_notices&amp;diff=65243"/>
		<updated>2012-02-29T13:55:36Z</updated>

		<summary type="html">&lt;p&gt;Jumpy972: /* See also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{RightTOC}}&lt;br /&gt;
Errors, warnings and notices can be displayed from any component, module, plugin or template using the methods outlined below.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
//Get a handle to the Joomla! application object&lt;br /&gt;
$app =&amp;amp; JFactory::getApplication(); &lt;br /&gt;
//add a message to the message queue&lt;br /&gt;
$app-&amp;gt;enqueueMessage( JText::_( &#039;Some error occurred&#039; ), &#039;error&#039; );&lt;br /&gt;
&lt;br /&gt;
/** Alternatively, in PHP 5 */&lt;br /&gt;
JFactory::getApplication()-&amp;gt;enqueueMessage( JText::_( &#039;Some error occurred&#039; ), &#039;error&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The second argument to the [[JApplication/enqueueMessage|enqueueMessage]] function is the type of the message. The default is &#039;message&#039;, but &#039;error&#039; results in a different style for the message.  The message will be displayed in place of a special &amp;lt;tt&amp;gt;jdoc:include&amp;lt;/tt&amp;gt; statement in your template.  Place the following in your template at the location where you want messages to appear.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;jdoc:include type=&amp;quot;message&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Message ==&lt;br /&gt;
&amp;lt;div style=&amp;quot;background-color: #c3d2e5; color: #0055bb; border-top: 3px solid #84a7db; border-bottom: 3px solid #84a7db; padding-left: 1em; font-weight: bold;&amp;quot;&amp;gt;&lt;br /&gt;
Message&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
/** PHP 4 */&lt;br /&gt;
$app = JFactory::getApplication();&lt;br /&gt;
$app-&amp;gt;enqueueMessage( &#039;Message&#039; );&lt;br /&gt;
&lt;br /&gt;
/** Alternatively, in PHP 5 */&lt;br /&gt;
JFactory::getApplication()-&amp;gt;enqueueMessage( &#039;Message&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Notice ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;background-color: #efe7b8; color: #c00; border-top: 3px solid #f0dc7e; border-bottom: 3px solid #f0dc7e; padding-left: 1em; font-weight: bold;&amp;quot;&amp;gt;&lt;br /&gt;
Notice&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JError::raiseNotice( 100, &#039;Notice&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Warning ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;background-color: #e6c0c0; color: #c00; border-top: 3px solid #DE7A7B; border-bottom: 3px solid #DE7A7B; padding-left: 1em; font-weight: bold;&amp;quot;&amp;gt;&lt;br /&gt;
Warning&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JError::raiseWarning( 100, &#039;Warning&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Error ==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JError::raiseError( 4711, &#039;A severe error occurred&#039; );&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[JError]]&lt;br /&gt;
* [[JApplication]]&lt;br /&gt;
*  [http://api.joomla.org/1.5/Joomla-Framework/Application/JApplication.html JApplication on api.joomla.org]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;noinclude&amp;gt;[[Category:Development]]&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
[[Category:Tutorials]][[Category:Component Development]]&lt;/div&gt;</summary>
		<author><name>Jumpy972</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=J1.5:Retrieving_and_Filtering_GET_and_POST_requests_with_JRequest::getVar&amp;diff=65242</id>
		<title>J1.5:Retrieving and Filtering GET and POST requests with JRequest::getVar</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=J1.5:Retrieving_and_Filtering_GET_and_POST_requests_with_JRequest::getVar&amp;diff=65242"/>
		<updated>2012-02-29T13:54:57Z</updated>

		<summary type="html">&lt;p&gt;Jumpy972: /* See also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;When writing any web application, it is crucial that you filter input data before using it. Joomla! provides a set of filtering libraries to help you accomplish this.&lt;br /&gt;
&lt;br /&gt;
===Defined in===&lt;br /&gt;
libraries\joomla\environment\request.php&lt;br /&gt;
&lt;br /&gt;
==Methods==&lt;br /&gt;
&lt;br /&gt;
=== &#039;getVar&#039; ===&lt;br /&gt;
To retrieve GET/POST request data, Joomla! uses the getVar method of the JRequest class (JRequest::getVar()).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Retrieving Data&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you have a form variable named &#039;address&#039;, you would want to use this code to get it:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$address = JRequest::getVar(&#039;address&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unless other parameters are set, all HTML and trailing whitespace will be filtered out.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The DEFAULT Parameter&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If you want to specify a default value in the event that &#039;address&#039; is not in the request or is unset, use this code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$address = JRequest::getVar(&#039;address&#039;, &#039;Address is empty&#039;);&lt;br /&gt;
echo $address;  // Address is empty&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The SOURCE Parameter&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Frequently, you will expect your variable to be found in a specific portion of the HTTP request (POST, GET, etc...). If this is the case, you should specify which portion; this will slightly increase your extension&#039;s security. If you expect &#039;address&#039; to only be in POST, use this code to enforce that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$address = JRequest::getVar(&#039;address&#039;, &#039;default value goes here&#039;, &#039;post&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The VARIABLE TYPE Parameter&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The fourth parameter of getVar() can be used to specify certain filters to force validation of specific value types for the variable. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$address = JRequest::getVar(&#039;address&#039;, &#039;default value goes here&#039;, &#039;post&#039;,&#039;variable type&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a list of types you can validate:&lt;br /&gt;
&lt;br /&gt;
*INT&lt;br /&gt;
*INTEGER&lt;br /&gt;
*FLOAT&lt;br /&gt;
*DOUBLE&lt;br /&gt;
*BOOL&lt;br /&gt;
*BOOLEAN&lt;br /&gt;
*WORD&lt;br /&gt;
*ALNUM&lt;br /&gt;
*CMD&lt;br /&gt;
*BASE64&lt;br /&gt;
*STRING&lt;br /&gt;
*ARRAY&lt;br /&gt;
*PATH&lt;br /&gt;
*USERNAME&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The FILTER MASK Parameter&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Finally, there are some mask constants you can pass in as the fifth parameter that allow you to bypass portions of the filtering:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$address = JRequest::getVar(&#039;address&#039;, &#039;default value goes here&#039;, &#039;post&#039;,&#039;validation type&#039;,mask type);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*JREQUEST_NOTRIM - prevents trimming of whitespace&lt;br /&gt;
*JREQUEST_ALLOWRAW - bypasses filtering&lt;br /&gt;
*JREQUEST_ALLOWHTML - allows most HTML. If this is not passed in, HTML is stripped out by default.&lt;br /&gt;
&lt;br /&gt;
Note. These are static variables not strings. Do not use quotes around them&lt;br /&gt;
&lt;br /&gt;
=== &#039;get&#039; ===&lt;br /&gt;
To receive a whole array filtered. If you would want to get the POST data, you can use this.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;JRequest::get( &#039;post&#039; )&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;nowiki&amp;gt;This returns the standard POST array.  You can use it on a template page if needed, or in the models section if convenient. It returns the most recent POST.&lt;br /&gt;
Methods of this object were not found in the Framework section where one would expect to find them. &amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [http://api.joomla.org/1.5/Joomla-Framework/Environment/JRequest.html JRequest on api.joomla.org]&lt;br /&gt;
* [[JURI]]&lt;br /&gt;
* [[JRoute]]&lt;br /&gt;
&lt;br /&gt;
==Security==&lt;br /&gt;
&lt;br /&gt;
Why not just use the Superglobals? If you are familiar with PHP already you may be wondering, why not just use $_GET / $_POST / $_REQUEST? To make Joomla more secure, all global variables should be read through this function. It removes the possibility for code injection and/or SQL injection. You can also define a default value (as you can see in line 6). Copied and changed from [[Creating a simple component - Part 1]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;/div&gt;</summary>
		<author><name>Jumpy972</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=J1.5:How_to_add_tooltips_to_your_Joomla!_website&amp;diff=65240</id>
		<title>J1.5:How to add tooltips to your Joomla! website</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=J1.5:How_to_add_tooltips_to_your_Joomla!_website&amp;diff=65240"/>
		<updated>2012-02-29T13:35:20Z</updated>

		<summary type="html">&lt;p&gt;Jumpy972: /* Create a Tooltip with the JHTML::tooltip Method */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A tooltips is a piece of text that pops up when you hover the mouse over a region on a website. If you use the Joomla! back end, for example, tooltips are used to help explain the action of different parameters, as shown in the screenshot below: &lt;br /&gt;
&lt;br /&gt;
[[Image:Screen_tooltip_example_20090208.png]]&lt;br /&gt;
&lt;br /&gt;
Tooltips are a great way to give the user access to information without using up space on the screen. You can use basic tooltips just by adding a &amp;quot;title&amp;quot; attribute to a tag. However, this doesn&#039;t give you the option to style the tooltips. With Joomla! version 1.5, it is very easy to add styled tooltips to your site. This tutorial will show you how. &amp;lt;blockquote&amp;gt;&#039;&#039;Note: If you are converting old code, make sure it doesn&#039;t use the prototype.js file.  That file will keep the tooltips from working.&#039;&#039;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Activate Tooltip Behavior ==&lt;br /&gt;
To start, you must activate the tooltip behavior.  This is done with the following line of code:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JHTML::_(&#039;behavior.tooltip&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Note that you only put this line in once per file. A good place is right after the &amp;lt;code&amp;gt;defined(&#039;_JEXEC&#039;) or die(&#039;Restricted access&#039;);&amp;lt;/code&amp;gt; line. If you are curious about what this line does, it inserts the following JavaScript code in the heading of the HTML page:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
    window.addEvent(&#039;domready&#039;, function(){ &lt;br /&gt;
       var JTooltips = new Tips($$(&#039;.hasTip&#039;), &lt;br /&gt;
       { maxTitleChars: 50, fixed: false}); &lt;br /&gt;
    });&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This allows tooltips to function, as outlined below.&lt;br /&gt;
&lt;br /&gt;
== Create a Tooltip with the JHTML::tooltip Method ==&lt;br /&gt;
One way to create a tooltip is using the JHTML::tooltip method. The API documentation is available at [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#tooltip http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#tooltip]. The method definition is shown below.  &lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
void tooltip (string $tooltip, [string $title = &#039;&#039;], [string $image = &#039;tooltip.png&#039;], &lt;br /&gt;
              [string $text = &#039;&#039;], [string $href = &#039;&#039;], [boolean $link = 1])&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The brackets mean the parameter is optional. The first parameter, &amp;quot;$tooltip&amp;quot;, is the only required parameter. The equals specifies the default if you do not pass that parameter. For example, the image file &#039;tooltip.png&#039; is the default image.&lt;br /&gt;
&lt;br /&gt;
The following is a basic tooltip.  Keep in mind that the image variable must be in reference to &#039;includes/js/ThemeOffice&#039;.  Use the prefix &#039;../../../&#039; to reference from the root of the Joomla installation.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JHTML::tooltip(&#039;This is the tooltip text&#039;, &#039;Tooltip title&#039;, &#039;tooltip.png&#039;, &#039;&#039;, &lt;br /&gt;
               &#039;http://www.joomla.org&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The above will make a tooltip using the default &amp;quot;tooltip.png&amp;quot; image, as shown below.[[Image:Tooltip_tutorial_example_screenshot_20090208.png|center|frame]]Clicking the image will take you to &amp;lt;tt&amp;gt;http://www.joomla.org&amp;lt;/tt&amp;gt;, since that is the &amp;quot;$href&amp;quot; argument. The HTML source for this tooltip is as follows:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;editlinktip hasTip&amp;quot; title=&amp;quot;Tooltip title::This is the tooltip text&amp;quot; &amp;gt;&lt;br /&gt;
&amp;lt;a href=&amp;quot;http://www.joomla.org&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;img src=&amp;quot;/my_joomla_path/includes/js/ThemeOffice/tooltip.png&amp;quot; border=&amp;quot;0&amp;quot; alt=&amp;quot;Tooltip&amp;quot;/&amp;gt;&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&#039;&#039;Internet Explorer Bug: As shown above, when you use the JHTML::tooltip method to create an image tooltip, it creates an &amp;quot;alt&amp;quot; attribute with the value &amp;quot;Tooltip&amp;quot;. The &amp;quot;alt&amp;quot; attribute is used in cases where the image file cannot be found or for accessibility (for example, for blind users). Internet Explorer automatically -- and incorrectly -- displays the &amp;quot;alt&amp;quot; attribute as a tooltip. This means that image tooltips created by JHTML::tooltip (like the example above) will display with two tooltips when viewed with Internet Explorer, as shown below.&#039;&#039;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
[[Image:Tooltip_tutorial_ie7bug_20090301.png|center|frame]]&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&#039;&#039;You can avoid this problem either by using text tooltips or by not using this method for image tooltips. Instead, just enter the HTML manually and set the &amp;quot;alt&amp;quot; attribute to an empty string (alt=&amp;quot;&amp;quot;).&#039;&#039;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code is almost the same as above except the image will not be a link (because the &amp;quot;$href&amp;quot; argument is omitted).&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JHTML::tooltip(&#039;This is the tooltip text&#039;, &#039;Tooltip title&#039;, &lt;br /&gt;
               &#039;tooltip.png&#039;, &#039;&#039;, &#039;&#039;, false);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A tooltip can be attached to an image or to text. For example, this code &lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
echo JHTML::tooltip(&#039;This is a tooltip attached to text&#039;, &#039;Text Tooltip Title&#039;, &lt;br /&gt;
	            &#039;&#039;, &#039;Hover on this text to see the tooltip&#039;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will show a tooltip attached to text, as shown below.&lt;br /&gt;
&lt;br /&gt;
[[Image:Tooltip_tutorial_example_screenshot2_20090208.png|center|frame]]&lt;br /&gt;
&lt;br /&gt;
Note that specifying the &amp;quot;$text&amp;quot; parameter will override any image you have passed to tooltip.&lt;br /&gt;
&lt;br /&gt;
== Create a Tooltip Using a CSS Class Name ==&lt;br /&gt;
If we look at the HTML page source generated by the &amp;lt;code&amp;gt;JHTML::tooltip&amp;lt;/code&amp;gt; function above, here is what we see:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;editlinktip hasTip&amp;quot; &lt;br /&gt;
      title=&amp;quot;Text Tooltip Title::This is a tooltip attached to text&amp;quot; &lt;br /&gt;
      style=&amp;quot;text-decoration: none; color: #333;&amp;quot;&amp;gt;&lt;br /&gt;
      Hover on this text to see the tooltip&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This function generates an HTML &amp;quot;span&amp;quot; tag with the classes &amp;quot;editlinktip&amp;quot; and &amp;quot;hasTip&amp;quot; and an attribute called &amp;quot;title&amp;quot;. Notice that the the &amp;quot;title&amp;quot; attribute has two parts, &amp;lt;code&amp;gt;&amp;lt;tooltip title&amp;gt;::&amp;lt;tooltip text&amp;gt;&amp;lt;/code&amp;gt; (for example, &amp;quot;Tooltip Title::This is the tooltip text&amp;quot;). You can create a tooltip with only text or with only a title. The title has implications for styling, as we&#039;ll see below.&lt;br /&gt;
&lt;br /&gt;
The Javascript inserted by the &amp;lt;code&amp;gt;JHTML::(&#039;behavior_tooltip&#039;)&amp;lt;/code&amp;gt; command we entered earlier picks up this tag based on the class called &amp;quot;hasTip&amp;quot;. So, a second way of creating a tooltip is to simply create a tag with a class called &amp;quot;hasTip&amp;quot; and an attribute of &amp;quot;title&amp;quot;. For example, this code&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;hasTip&amp;quot; &lt;br /&gt;
   title=&amp;quot;Text Tooltip Title::This is a tooltip attached to text&amp;quot;&amp;gt;&lt;br /&gt;
   Hover on this text to see the tooltip&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
will produce exactly the same effect as the &amp;lt;code&amp;gt;JHTML::tooltip()&amp;lt;/code&amp;gt; example above.&lt;br /&gt;
&lt;br /&gt;
== Adding CSS Styling to the Tooltip ==&lt;br /&gt;
The default tooltips, whether using the JHTML::tooltip method or class method, use the following three CSS classes: &amp;lt;tt&amp;gt;.tool-tip&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;.tool-title&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;.tool-text&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Here are the default styles.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;css&amp;quot;&amp;gt;&lt;br /&gt;
/* Tooltips */&lt;br /&gt;
.tool-tip {&lt;br /&gt;
   float: left;&lt;br /&gt;
   background: #ffc;&lt;br /&gt;
   border: 1px solid #D4D5AA;&lt;br /&gt;
   padding: 5px;&lt;br /&gt;
   max-width: 200px;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
.tool-title {&lt;br /&gt;
   padding: 0;&lt;br /&gt;
   margin: 0;&lt;br /&gt;
   font-size: 100%;&lt;br /&gt;
   font-weight: bold;&lt;br /&gt;
   margin-top: -15px;&lt;br /&gt;
   padding-top: 15px;&lt;br /&gt;
   padding-bottom: 5px;&lt;br /&gt;
   background: url(../images/selector-arrow.png) no-repeat;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
.tool-text {&lt;br /&gt;
   font-size: 100%;&lt;br /&gt;
   margin: 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adding CSS Styling to the Tooltip Joomla v1.6+==&lt;br /&gt;
The default tooltips, whether using the JHTML::tooltip method or class method, use the following three CSS classes: &amp;lt;tt&amp;gt;.tip&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;.tip-title&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;.tip-text&amp;lt;/tt&amp;gt; plus a wrapper class &amp;lt;tt&amp;gt;.tip-wrap&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Here are the default styles.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;css&amp;quot;&amp;gt;&lt;br /&gt;
/* Tooltips */&lt;br /&gt;
.tip-wrap{&lt;br /&gt;
    z-index: 10000;&lt;br /&gt;
}&lt;br /&gt;
.tip {&lt;br /&gt;
   float: left;&lt;br /&gt;
   background: #ffc;&lt;br /&gt;
   border: 1px solid #D4D5AA;&lt;br /&gt;
   padding: 5px;&lt;br /&gt;
   max-width: 200px;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
.tip-title {&lt;br /&gt;
   padding: 0;&lt;br /&gt;
   margin: 0;&lt;br /&gt;
   font-size: 100%;&lt;br /&gt;
   font-weight: bold;&lt;br /&gt;
   margin-top: -15px;&lt;br /&gt;
   padding-top: 15px;&lt;br /&gt;
   padding-bottom: 5px;&lt;br /&gt;
   background: url(../images/selector-arrow.png) no-repeat;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
.tip-text {&lt;br /&gt;
   font-size: 100%;&lt;br /&gt;
   margin: 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have a custom CSS file, copy this code and alter it to your liking. Note that the &amp;lt;tt&amp;gt;.tool-title&amp;lt;/tt&amp;gt; (&amp;lt;tt&amp;gt;.tip-title&amp;lt;/tt&amp;gt; Joomla v1.6+) class uses by default the &amp;quot;selector-arrow.png&amp;quot; image. This is what gives the outline of the tooltip the little pointer in the upper left of the tooltip box. If you leave out a title in your tooltip, you will just get a rectangle, without the pointer.&lt;br /&gt;
&lt;br /&gt;
== Customizing Your Tooltips ==&lt;br /&gt;
Ok, now it&#039;s time to have some fun. The &amp;lt;code&amp;gt;JHTML::_(&#039;behavior.tooltip&#039;)&amp;lt;/code&amp;gt; can take two optional parameters. The first parameter is the name of the CSS class that will be used to identify the tooltip. As we saw earlier, this defaults to &amp;quot;hasTip&amp;quot;. The second optional parameter is an array of parameters that you can use to fine-tune the tooltip functionality. These are explained below. &lt;br /&gt;
* &#039;&#039;&#039;maxTitleChars:&#039;&#039;&#039; The maximum length of the title (the part of the &amp;quot;title&amp;quot; attribute before the &amp;quot;::&amp;quot;)&lt;br /&gt;
* &#039;&#039;&#039;showDelay, hideDelay:&#039;&#039;&#039; The time to delay showing or hiding the tooltip, in milliseconds. Default is 100.&lt;br /&gt;
* &#039;&#039;&#039;className:&#039;&#039;&#039; The first part of the class name used to style the actual tooltip. The default, as we saw, is &amp;quot;tool&amp;quot;, and the full class names by default are &amp;quot;tool-tip&amp;quot;, &amp;quot;tool-title&#039;, and &amp;quot;tool-text&amp;quot;. So, for example, if we set this to &amp;quot;custom&amp;quot;, we would style the classes &amp;quot;custom-tip&amp;quot;, &amp;quot;custom-title&amp;quot;, and &amp;quot;custom-text&amp;quot;.&lt;br /&gt;
* &#039;&#039;&#039;fixed:&#039;&#039;&#039; Whether or not to have the tooltip move with the mouse. If set to &amp;quot;true&amp;quot;, the tooltip will be centered below the text or image. If set to &amp;quot;false&amp;quot;, the tooltip will move with the mouse. Default is &amp;quot;false&amp;quot;. &lt;br /&gt;
* &#039;&#039;&#039;onShow, onHide:&#039;&#039;&#039; Functions to call for the onShow and onHide events. We&#039;ll see an example below where we can use these to create a fade-in and fade-out for the tooltip.&lt;br /&gt;
&lt;br /&gt;
In the next section, we&#039;ll show how to use these parameters with some examples.&lt;br /&gt;
&lt;br /&gt;
== Tooltip With Different Classes ==&lt;br /&gt;
In this example, we will create a tooltip using different selector and tooltip styling classes. Why might we want to do this? One reason would be if we had different types of tooltips and we wanted to style them differently.&lt;br /&gt;
&lt;br /&gt;
Here is the code to create the tooltip Javascript function:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$toolTipArray = array(&#039;className&#039;=&amp;gt;&#039;custom2&#039;);&lt;br /&gt;
JHTML::_(&#039;behavior.tooltip&#039;, &#039;.hasTip2&#039;, $toolTipArray);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In this code, we are creating an array with just one element -- to set the &amp;quot;className&amp;quot; parameter to &amp;quot;custom2&amp;quot;. This means that, to style these tooltips, we would use the classes &amp;lt;tt&amp;gt;custom2-tip&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;custom2-title&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;custom2-text&amp;lt;/tt&amp;gt;. Then we call the method with the arguments &amp;quot;.hasTip2&amp;quot; and the array &amp;quot;$toolTipArray&amp;quot;. It can be a little confusing, because we have two CSS classes at work here. The class &amp;quot;.hasTip2&amp;quot; is used in the HTML tag. That is how the Javascript program identifies the tooltips to operate on. The class &amp;quot;custom2&amp;quot; is used as the first part of the three CSS classes to use to style the actual tooltip itself.&lt;br /&gt;
&lt;br /&gt;
To use this new tooltip, we could use the following code:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;hasTip2&amp;quot; &lt;br /&gt;
	title=&amp;quot;My Tooltip Title :: Tooltip text for hasTip2 class with custom2 style classes.&amp;quot;&amp;gt;&lt;br /&gt;
	hasTip2 and custom2 example&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Since we set the class to &amp;quot;hasTip2&amp;quot;, this tag will be processed by the new version of the tooltip program. So, if we use both the default tooltip (&amp;quot;hasTip&amp;quot; class) and the new tooltip (&amp;quot;hasTip2&amp;quot; class) in the same page, we can style them differently using &amp;quot;tool-&amp;quot; styles for the default and &amp;quot;custom2-&amp;quot; styles for the &amp;quot;hasTip2&amp;quot; tooltips.&lt;br /&gt;
&lt;br /&gt;
Next, let&#039;s look at a more complex example, shown below.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$toolTipArray = array(&#039;className&#039; =&amp;gt; &#039;custom2&#039;, &#039;showDelay&#039;=&amp;gt;&#039;500&#039;, &lt;br /&gt;
   &#039;hideDelay&#039;=&amp;gt;&#039;500&#039;, &#039;fixed&#039;=&amp;gt;true,&lt;br /&gt;
   &#039;onShow&#039;=&amp;gt;&amp;quot;function(tip) {tip.effect(&#039;opacity&#039;, &lt;br /&gt;
      {duration: 500, wait: false}).start(0,1)}&amp;quot;, &lt;br /&gt;
   &#039;onHide&#039;=&amp;gt;&amp;quot;function(tip) {tip.effect(&#039;opacity&#039;, &lt;br /&gt;
      {duration: 500, wait: false}).start(1,0)}&amp;quot;);&lt;br /&gt;
JHTML::_(&#039;behavior.tooltip&#039;, &#039;.hasTip2&#039;, $toolTipArray); ?&amp;gt; &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Again, we are building an array to pass to the &amp;lt;code&amp;gt;JHTML::_(&#039;behavior.tooltip&#039;)&amp;lt;/code&amp;gt; function. Again, we are setting the &amp;quot;className&amp;quot; parameter to &amp;quot;custom2&amp;quot;. We are also setting the &amp;quot;showDelay&amp;quot; and &amp;quot;hideDelay&amp;quot; parameters to 500 milliseconds (.5 seconds). So the tooltip will show only after the mouse has hovered for this amount of time. &lt;br /&gt;
&lt;br /&gt;
Notice that we are setting the parameter &amp;quot;fixed&amp;quot; to &amp;quot;true&amp;quot; (without the quotes). This means that the tooltip will not move with the mouse. Instead, it will always show centered below the tooltip text or image.&lt;br /&gt;
&lt;br /&gt;
Finally, the tricky part. We are creating functions to pass in to the &amp;quot;onShow&amp;quot; and &amp;quot;onHide&amp;quot; events. These functions cause the tooltip to fade in and fade out over the space of 500 milliseconds. This is done by gradually varying the tooltip&#039;s CSS &amp;quot;opacity&amp;quot; style from &amp;quot;0&amp;quot; (completely transparent) to &amp;quot;1&amp;quot; (completely opaque). If we wanted the tooltip to be partially transparent, we could change these to &amp;lt;code&amp;gt;start(0,.8)&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;start(.8,0)&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
These functions are similar to the sample code in the [http://demos111.mootools.net/Tips MooTools demo tutorial]. Click on the link called &amp;quot;js code&amp;quot; and look at the code for the &amp;quot;Tips2&amp;quot; demo. We have just taken the code from the initialize function and incorporated it into the &amp;quot;onShow&amp;quot; and &amp;quot;onHide&amp;quot; functions.&lt;br /&gt;
&lt;br /&gt;
The last line of code above creates the actual Javascript code in our Joomla! document. If we show the page and view source, we see the following:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
window.addEvent(&#039;domready&#039;, function(){ &lt;br /&gt;
   var JTooltips = new Tips($$(&#039;.hasTip2&#039;), {&lt;br /&gt;
      maxTitleChars: 50, showDelay: 500, hideDelay: 500, className: &#039;custom2&#039;, &lt;br /&gt;
         fixed: true, &lt;br /&gt;
      onShow: function(tip) {tip.effect(&#039;opacity&#039;, {duration: 500, wait: false}).start(0,1)}, &lt;br /&gt;
      onHide: function(tip) {tip.effect(&#039;opacity&#039;, {duration: 500, wait: false}).start(1,0)}&lt;br /&gt;
   }); &lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
So we can see the effect of the parameters that we passed to the &amp;lt;code&amp;gt;JHTML::_(&#039;behavior.tooltip&#039;)&amp;lt;/code&amp;gt; method.&lt;br /&gt;
&lt;br /&gt;
=== offsets Parameter ===&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&#039;&#039;Note: The &amp;quot;offsets&amp;quot; parameter doesn&#039;t work in version 1.5.9 and earlier because of a bug. As of version 1.5.10 it should work as outlined below.&#039;&#039;&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
You can control the x and y distance, in pixels, from the cursor to the tooltip using the &amp;quot;offsets&amp;quot; parameter. This parameter must be an array as shown in the example code below:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
// set x (horizontal) distance to 20 pixels, y (vertical) distance to 30 pixels&lt;br /&gt;
$toolTipArray = array(&#039;offsets&#039;=&amp;gt;array(&#039;x&#039;=&amp;gt;20, &#039;y&#039;=&amp;gt;30), &#039;maxtitlechars&#039;=&amp;gt;40);&lt;br /&gt;
JHTML::_(&#039;behavior.tooltip&#039;, &#039;.customOffset&#039;, $toolTipArray);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using an External Javascript File ==&lt;br /&gt;
There are times when you might prefer to work with a separate Javascript file. This gives you complete flexibility to use all of the mootools capabilities. To do this:&lt;br /&gt;
# Create the separate Javascript file and save it somewhere in your Joomla! site (for example, &amp;quot;templates/&amp;lt;your template&amp;gt;/js/yourjsfile.js&amp;quot;.&lt;br /&gt;
# Use the &amp;lt;code&amp;gt;JHTML::script&amp;lt;/code&amp;gt; function to add this script to your document. For example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
   $filename = &#039;testtooltip.js&#039;; // this file is used for class=&amp;quot;hasTip3&amp;quot; titles&lt;br /&gt;
   $path = &#039;templates/rhuk_milkyway/js/&#039;; // path to the file&lt;br /&gt;
   // true means MooTools will load if it is not already loaded&lt;br /&gt;
   JHTML::script($filename, $path, true); &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This will load your script into the document and make sure that the MooTools library is available.&lt;br /&gt;
&lt;br /&gt;
== Complete Code Example ==&lt;br /&gt;
Here is an example that incorporates all of the elements discussed in this tutorial. So you can see the code in action, we will create an override of the &amp;quot;mod_stats&amp;quot; Module and add our test code there. We will use the rhuk_milkyway template.&lt;br /&gt;
&lt;br /&gt;
To set up the template override, create a folder called &amp;quot;templates/rhuk_milkyway/html/mod_stats&amp;quot; and copy the file &amp;quot;modules/mod_stats/tmpl/default.php&amp;quot; to this new folder.&lt;br /&gt;
&lt;br /&gt;
After line 2 of this file (&amp;lt;code&amp;gt;defined(&#039;_JEXEC&#039;) or die(&#039;Restricted access&#039;);&amp;lt;/code&amp;gt;), insert the following:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
JHTML::_(&#039;behavior.tooltip&#039;);&lt;br /&gt;
$toolTipArray = array(&#039;className&#039; =&amp;gt; &#039;custom2&#039;, &#039;showDelay&#039;=&amp;gt;&#039;500&#039;, &#039;hideDelay&#039;=&amp;gt;&#039;500&#039;, &lt;br /&gt;
   &#039;fixed&#039;=&amp;gt;true &lt;br /&gt;
   , &#039;onShow&#039;=&amp;gt;&amp;quot;function(tip) {tip.effect(&#039;opacity&#039;, &lt;br /&gt;
        {duration: 500, wait: false}).start(0,1)}&amp;quot;&lt;br /&gt;
   , &#039;onHide&#039;=&amp;gt;&amp;quot;function(tip) {tip.effect(&#039;opacity&#039;, &lt;br /&gt;
        {duration: 500, wait: false}).start(1,0)}&amp;quot;);&lt;br /&gt;
JHTML::_(&#039;behavior.tooltip&#039;, &#039;.hasTip2&#039;, $toolTipArray);  // class=&amp;quot;hasTip2&amp;quot; titles&lt;br /&gt;
$filename = &#039;testtooltip.js&#039;; // used for class=&amp;quot;hasTip3&amp;quot; titles&lt;br /&gt;
$path = &#039;templates/rhuk_milkyway/js/&#039;;&lt;br /&gt;
JHTML::script($filename, $path, true); // MooTools will load if it is not already loaded&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Here we are creating the Javascript functions we will need later. The first line is the simple default declaration that will use the &amp;quot;.hasTip&amp;quot; and &amp;quot;tool-&amp;quot; CSS classes. &lt;br /&gt;
&lt;br /&gt;
The next 5 lines create the more customized function that includes the fade-in and fade-out. It uses the &amp;quot;.hasTip2&amp;quot; to create the tip and the classes starting with &amp;quot;custom2-&amp;quot; to style the tooltip.&lt;br /&gt;
&lt;br /&gt;
The last 3 lines reference the external Javascript file, which will be created below. The class information will be contained in that file.&lt;br /&gt;
&lt;br /&gt;
Now, time for some more coding. At the end of the &amp;quot;modules/mod_stats/tmpl/default.php&amp;quot; file, add the code shown below:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;Tooltip Examples&amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;?php echo JHTML::tooltip(&#039;This is the tooltip text&#039;, &#039;Tooltip title&#039;, &lt;br /&gt;
	&#039;tooltip.png&#039;, &#039;&#039;, &#039;http://www.joomla.org&#039;);?&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;?php echo JHTML::tooltip(&#039;This is a tooltip attached to text&#039;, &#039;Text Tooltip Title&#039;, &lt;br /&gt;
	&#039;&#039;, &#039;Hover on this text to see the tooltip&#039;);?&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;							&lt;br /&gt;
&amp;lt;a class=&amp;quot;hasTip&amp;quot; title=&amp;quot;My Title::Tooltip on &#039;a&#039; tag text using default &#039;hasTip&#039; class&amp;quot; &lt;br /&gt;
	href=&amp;quot;http://www.joomla.org&amp;quot;&amp;gt;Tooltip on a link example&amp;lt;/a&amp;gt; &lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;hasTip2&amp;quot; &lt;br /&gt;
	title=&amp;quot;My Tooltip Title :: Tooltip text for hasTip2 class with custom2 style classes.&amp;quot;&amp;gt;&lt;br /&gt;
	hasTip2 and custom2 example&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;hasTip3&amp;quot; &lt;br /&gt;
	title=&amp;quot;hasTip3 Title::This is using class &#039;hasTip3&#039; using external JS script.&amp;quot;&amp;gt;&lt;br /&gt;
           hasTip3 hover text&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The first two examples using the &amp;lt;code&amp;gt;JHTML::tooltip&amp;lt;/code&amp;gt; function to create the tooltip HTML code. &lt;br /&gt;
&lt;br /&gt;
The third example shows an &amp;quot;a&amp;quot; tag with a tooltip. This illustrates that you can put tooltips on most HTML tags, not just &amp;quot;span&amp;quot; tags. Again, it is using the &amp;quot;hasTip&amp;quot; class, so it will be controlled by the Javascript above called with the &amp;quot;.hasTip&amp;quot; argument and will be styled with the default &amp;quot;tool-&amp;quot; styles.&lt;br /&gt;
&lt;br /&gt;
The fourth example shows a &amp;quot;span&amp;quot; tag using the &amp;quot;hasTip2&amp;quot; class. So it will be styled using the &amp;quot;custom2-&amp;quot; classes and will have the &amp;quot;showDelay&amp;quot; and &amp;quot;hideDelay&amp;quot; of 500 milliseconds and have &amp;quot;fixed&amp;quot; equal to &amp;quot;true&amp;quot; (so the tip will not move with the mouse). Also, it uses the special fade-in and fade-out effects. &lt;br /&gt;
&lt;br /&gt;
The last example will use the Javascript code from the external file, shown below.&lt;br /&gt;
&lt;br /&gt;
Now, some more coding. Create a JavaScript file called &amp;quot;testtooltip.js&amp;quot; and save it into the folder &amp;quot;templates/rhuk_milkyway/js&amp;quot;:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
window.addEvent(&#039;domready&#039;, function(){&lt;br /&gt;
	   //do your tips stuff in here...&lt;br /&gt;
	   var zoomTip = new Tips($$(&#039;.hasTip3&#039;), {&lt;br /&gt;
	      className: &#039;custom3&#039;, //this is the prefix for the CSS class&lt;br /&gt;
	      offsets: {&lt;br /&gt;
	  		&#039;x&#039;: 20,       //default is 16&lt;br /&gt;
	  		&#039;y&#039;: 30        //default is 16&lt;br /&gt;
              },&lt;br /&gt;
	      initialize:function(){&lt;br /&gt;
	         this.fx = new Fx.Style(this.toolTip, &#039;opacity&#039;, &lt;br /&gt;
	        		 {duration: 1000, wait: false}).set(0);&lt;br /&gt;
	      },&lt;br /&gt;
	      onShow: function(toolTip) {&lt;br /&gt;
	         this.fx.start(0,.8);&lt;br /&gt;
	      },&lt;br /&gt;
	      onHide: function(toolTip) {&lt;br /&gt;
	         this.fx.start(.8,0);&lt;br /&gt;
	      }&lt;br /&gt;
	   });&lt;br /&gt;
	});&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This code will operate on the &amp;quot;hasTip3&amp;quot; class and will use style classes starting with &amp;quot;custom3-&amp;quot;. We are setting the x distance (from the cursor to the tooltip) to 20 pixels and the y distance to 30 pixels. This also has the fade-in and fade-out functionality, but the final &amp;quot;opacity&amp;quot; value is set to .8, meaning that the tooltip will be slightly transparent.&lt;br /&gt;
&lt;br /&gt;
Finally, add this to the end of your &amp;quot;templates/rhuk_milkyway/css/template.css&amp;quot; file:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;css&amp;quot;&amp;gt;&lt;br /&gt;
.custom2-tip {&lt;br /&gt;
	color: #000;&lt;br /&gt;
	width: 130px;&lt;br /&gt;
	z-index: 13000;&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
.custom2-title {&lt;br /&gt;
	font-weight: bold;&lt;br /&gt;
	font-size: 11px;&lt;br /&gt;
	margin: 0;&lt;br /&gt;
	color: #024A68;&lt;br /&gt;
	padding: 8px 8px 4px;&lt;br /&gt;
	background: #3CA0D0;&lt;br /&gt;
	border-bottom: 1px solid #024A68;&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
.custom2-text {&lt;br /&gt;
	font-size: 11px;&lt;br /&gt;
	padding: 4px 8px 8px;&lt;br /&gt;
	background: #63ADD0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
.custom3-tip {&lt;br /&gt;
	color: #000;&lt;br /&gt;
	width: 130px;&lt;br /&gt;
	z-index: 13000;&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
.custom3-title {&lt;br /&gt;
	font-weight: bold;&lt;br /&gt;
	font-size: 11px;&lt;br /&gt;
	margin: 0;&lt;br /&gt;
	color: #3E4F14;&lt;br /&gt;
	padding: 8px 8px 4px;&lt;br /&gt;
	background: #C3DF7D;&lt;br /&gt;
	border-bottom: 1px solid #B5CF74;&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
.custom3-text {&lt;br /&gt;
	font-size: 11px;&lt;br /&gt;
	padding: 4px 8px 8px;&lt;br /&gt;
	background: #CFDFA7;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Here we are just adding different colors for the &amp;quot;custom2-&amp;quot; and &amp;quot;custom3-&amp;quot; styles so you can see the effect of the different tooltip code.&lt;br /&gt;
&lt;br /&gt;
Notice that &amp;lt;tt&amp;gt;.custom2-title&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;.custom3-title&amp;lt;/tt&amp;gt; classes do not have a background property. So these tooltips will be a box without the neat little arrow pointing at the mouse. If you wanted, you could create an image similar to &amp;quot;templates/system/images/selector-arrow.png&amp;quot; of the right color and add that as a background to these classes.&lt;br /&gt;
&lt;br /&gt;
== Example Code Screenshots ==&lt;br /&gt;
Here are some screenshots taken from the sample code above. The first screenshot shows the modified &amp;quot;mod_stats&amp;quot; modules with our sample code.&lt;br /&gt;
[[Image:Screen_tooltip_example2_20090210.png|center|frame]]&lt;br /&gt;
The screenshot below shows the fade-in effect for the &amp;quot;.hasTip2&amp;quot; tooltip. Notice also that the tooltip is centered below the text. This is the effect of setting &amp;quot;fixed&amp;quot; equal to &amp;quot;true&amp;quot;.&lt;br /&gt;
[[Image:Screen_tooltip_example1_20090209.png|center|frame]]&lt;br /&gt;
The last screenshot shows the different styling for the &amp;quot;.hasTip3&amp;quot; tooltip, based on the &amp;quot;custom3-&amp;quot; CSS class styles. &lt;br /&gt;
[[Image:Screen_tooltip_example3_20090210.png|center|frame]]&lt;br /&gt;
&lt;br /&gt;
== More Information ==&lt;br /&gt;
More information about the topics covered in this tutorial is available at the links below. Note that Joomla! version 1.5 uses MooTools version 1.11. The current version of MooTools is 1.2.&lt;br /&gt;
* Joomla API - [http://api.joomla.org http://api.joomla.org]&lt;br /&gt;
* Documentation for 1.11 MooTools Tips: [http://docs111.mootools.net/Plugins/Tips.js http://docs111.mootools.net/Plugins/Tips.js]&lt;br /&gt;
* Mootools demos for version 1.11 - [http://demos111.mootools.net/Tips http://demos111.mootools.net/Tips]&lt;br /&gt;
* Mootools Website - [http://www.mootools.net/ http://www.mootools.net/]&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>Jumpy972</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=J1.5:Developing_a_MVC_Component/Using_the_Database&amp;diff=65239</id>
		<title>J1.5:Developing a MVC Component/Using the Database</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=J1.5:Developing_a_MVC_Component/Using_the_Database&amp;diff=65239"/>
		<updated>2012-02-29T13:34:30Z</updated>

		<summary type="html">&lt;p&gt;Jumpy972: /* Retrieving the Data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
In the first two tutorials, we showed you how to build a simple model-view-controller component. We had one view which retrieved data from a model (which was created in the 2nd tutorial). In this tutorial, we will be working with the model. Instead of the data being hard coded in the model, the model will retrieve the data from a table in the database.&lt;br /&gt;
&lt;br /&gt;
This tutorial will demonstrate how to use the JDatabase class to retrieve data from the database.&lt;br /&gt;
&lt;br /&gt;
== Retrieving the Data ==&lt;br /&gt;
&lt;br /&gt;
Our model currently has one method: getGreeting(). This method is very simple - all it does is return the hard-coded greeting.&lt;br /&gt;
&lt;br /&gt;
To make things more interesting, we will load the greeting from a database table. We will demonstrate later how to create an SQL file and add the appropriate code to the XML manifest file so that the table and some sample data will be created when the component is installed. For now, we will simply replace our return statement with some code that will retrieve the greeting from the database and return it.&lt;br /&gt;
&lt;br /&gt;
The first step is to obtain a reference to a database object. Since Joomla! uses the database for its normal operation, a database connection already exists; therefore, it is not necessary to create your own. A reference to the existing database can be obtained using:&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;$db =&amp;amp; JFactory::getDBO();&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
JFactory is a static class that is used to retrieve references to many of the system objects. More information about this class can be found in the API documentation [http://docs.joomla.org/JFactory JFactoryAPI].&lt;br /&gt;
&lt;br /&gt;
The method name (getDBO) stands for get DataBase Object, and is easy and important to remember.&lt;br /&gt;
&lt;br /&gt;
Now that we have obtained a reference to the database object, we can retrieve our data. We do this in two steps:&lt;br /&gt;
&lt;br /&gt;
* store our query in the database object&lt;br /&gt;
* load the result&lt;br /&gt;
&lt;br /&gt;
Our new getGreeting() method will therefore look like:&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;function getGreeting()&lt;br /&gt;
{&lt;br /&gt;
   $db =&amp;amp; JFactory::getDBO();&lt;br /&gt;
&lt;br /&gt;
   $query = &#039;SELECT greeting FROM #__hello&#039;;&lt;br /&gt;
   $db-&amp;gt;setQuery( $query );&lt;br /&gt;
   $greeting = $db-&amp;gt;loadResult();&lt;br /&gt;
&lt;br /&gt;
   return $greeting;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
hello is the name of the table that we will create later, and greeting is the name of the field that stores the greetings. If you are not familiar with SQL, it would be helpful to take a tutorial or a lesson to get yourself up to speed. There are many such tutorials on the web and they are easily found using search engines.&lt;br /&gt;
&lt;br /&gt;
The $db-&amp;gt;loadResult() method will execute the stored database query and return the first field of the first row of the result. See [http://api.joomla.org/1.5/Joomla-Framework/Database/JDatabase.html JDatabase API reference] for more information about other load methods in the JDatabase class.&lt;br /&gt;
&lt;br /&gt;
== Creating the Installation SQL File ==&lt;br /&gt;
&lt;br /&gt;
The Joomla! installer has built-in support for executing queries during component installation. These queries are all stored in a standard text file.&lt;br /&gt;
&lt;br /&gt;
We will have three queries in our install file: the first will drop the table in case it already exists, the second will create the table with the appropriate fields, and the third will insert the data.&lt;br /&gt;
&lt;br /&gt;
Here are our queries:&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;DROP TABLE IF EXISTS `#__hello`;&lt;br /&gt;
&lt;br /&gt;
CREATE TABLE `#__hello` (&lt;br /&gt;
  `id` int(11) unsigned NOT NULL auto_increment,&lt;br /&gt;
  `greeting` varchar(25) NOT NULL,&lt;br /&gt;
  PRIMARY KEY  (`id`)&lt;br /&gt;
) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;&lt;br /&gt;
&lt;br /&gt;
INSERT INTO `#__hello` (`greeting`) VALUES (&#039;Hello, World!&#039;), (&#039;Bonjour, Monde!&#039;), (&#039;Ciao, Mondo!&#039;);&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You might find the  prefix on the table names rather odd. Joomla! will replace this prefix with the prefix used by the current install. For most installs, this table will become jos_hello. This allows multiple installs of Joomla! to use the same database, and prevents collisions with other applications using the same table names (i.e. two applications might share a database, but might both require a &#039;users&#039; table. This convention avoids problems.)&lt;br /&gt;
&lt;br /&gt;
We have specified two fields in our database. The first field is id, and is called the &#039;primary key&#039;. The primary key of a database table is a field that is used to uniquely identify a record. This is often used to lookup rows in the database. The other field is greeting. This is the field that stores the greeting that is returned from the query that we used above.&lt;br /&gt;
&lt;br /&gt;
We will save our installation queries in a file called admin/install.sql. (Note: In the original version of this file, install.utf.sql was used - this was incorrect. Also see [[Talk:Developing_a_Model-View-Controller_Component_-_Part_3_-_Using_the_Database | discussion]].)&lt;br /&gt;
&lt;br /&gt;
=== Creating the Uninstall SQL File ===&lt;br /&gt;
&lt;br /&gt;
Though we might hope that people will never want to &amp;quot;uninstall&amp;quot; our component, it is important that if they do, nothing is left behind after uninstalling our component. Joomla! will look after deleting the files and directories that were created during the &amp;quot;install&amp;quot;, but we must manually include queries that will remove any tables that were added to the database. Since we have only created one table, we only need one query:&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;DROP TABLE IF EXISTS `#__hello`;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We will save this uninstall query in a file called admin/uninstall.sql. (Note: In the original version of this file, uninstall.utf.sql was used - this was incorrect. Also see [[Talk:Developing_a_Model-View-Controller_Component_-_Part_3_-_Using_the_Database | discussion]].)&lt;br /&gt;
&lt;br /&gt;
== Updating our XML File ==&lt;br /&gt;
&lt;br /&gt;
We need to change a few things in our hello.xml file. First, we need to add our two new sql files to the list of files to install. Secondly, the SQL install files have to be placed in the admin directory. Thirdly, we need to tell the installer to execute the queries in our files on install and uninstall.&lt;br /&gt;
&lt;br /&gt;
Our new file looks like this:&lt;br /&gt;
 &lt;br /&gt;
&amp;lt;source lang=&amp;quot;xml&amp;quot;&amp;gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;&lt;br /&gt;
&amp;lt;install type=&amp;quot;component&amp;quot; version=&amp;quot;1.5.0&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;lt;name&amp;gt;Hello&amp;lt;/name&amp;gt;&lt;br /&gt;
 &amp;lt;!-- The following elements are optional and free of formatting constraints --&amp;gt;&lt;br /&gt;
 &amp;lt;creationDate&amp;gt;2007-02-22&amp;lt;/creationDate&amp;gt;&lt;br /&gt;
 &amp;lt;author&amp;gt;John Doe&amp;lt;/author&amp;gt;&lt;br /&gt;
 &amp;lt;authorEmail&amp;gt;john.doe@example.org&amp;lt;/authorEmail&amp;gt;&lt;br /&gt;
 &amp;lt;authorUrl&amp;gt;http://www.example.org&amp;lt;/authorUrl&amp;gt;&lt;br /&gt;
 &amp;lt;copyright&amp;gt;Copyright Info&amp;lt;/copyright&amp;gt;&lt;br /&gt;
 &amp;lt;license&amp;gt;License Info&amp;lt;/license&amp;gt;&lt;br /&gt;
 &amp;lt;!--  The version string is recorded in the components table --&amp;gt;&lt;br /&gt;
 &amp;lt;version&amp;gt;3.01&amp;lt;/version&amp;gt;&lt;br /&gt;
 &amp;lt;!-- The description is optional and defaults to the name --&amp;gt;&lt;br /&gt;
 &amp;lt;description&amp;gt;Description of the component ...&amp;lt;/description&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;!-- Site Main File Copy Section --&amp;gt;&lt;br /&gt;
 &amp;lt;!-- Note the folder attribute: This attribute describes the folder&lt;br /&gt;
      to copy FROM in the package to install therefore files copied&lt;br /&gt;
      in this section are copied from /site/ in the package --&amp;gt;&lt;br /&gt;
 &amp;lt;files folder=&amp;quot;site&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;filename&amp;gt;controller.php&amp;lt;/filename&amp;gt;&lt;br /&gt;
  &amp;lt;filename&amp;gt;hello.php&amp;lt;/filename&amp;gt;&lt;br /&gt;
  &amp;lt;filename&amp;gt;index.html&amp;lt;/filename&amp;gt;&lt;br /&gt;
  &amp;lt;filename&amp;gt;models/hello.php&amp;lt;/filename&amp;gt;&lt;br /&gt;
  &amp;lt;filename&amp;gt;models/index.html&amp;lt;/filename&amp;gt;&lt;br /&gt;
  &amp;lt;filename&amp;gt;views/index.html&amp;lt;/filename&amp;gt;&lt;br /&gt;
  &amp;lt;filename&amp;gt;views/hello/index.html&amp;lt;/filename&amp;gt;&lt;br /&gt;
  &amp;lt;filename&amp;gt;views/hello/view.html.php&amp;lt;/filename&amp;gt;&lt;br /&gt;
  &amp;lt;filename&amp;gt;views/hello/tmpl/default.php&amp;lt;/filename&amp;gt;&lt;br /&gt;
  &amp;lt;filename&amp;gt;views/hello/tmpl/index.html&amp;lt;/filename&amp;gt;&lt;br /&gt;
 &amp;lt;/files&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;install&amp;gt;&lt;br /&gt;
  &amp;lt;sql&amp;gt;&lt;br /&gt;
    &amp;lt;file charset=&amp;quot;utf8&amp;quot; driver=&amp;quot;mysql&amp;quot;&amp;gt;install.sql&amp;lt;/file&amp;gt;&lt;br /&gt;
  &amp;lt;/sql&amp;gt;&lt;br /&gt;
 &amp;lt;/install&amp;gt;&lt;br /&gt;
 &amp;lt;uninstall&amp;gt;&lt;br /&gt;
  &amp;lt;sql&amp;gt;&lt;br /&gt;
    &amp;lt;file charset=&amp;quot;utf8&amp;quot; driver=&amp;quot;mysql&amp;quot;&amp;gt;uninstall.sql&amp;lt;/file&amp;gt;&lt;br /&gt;
  &amp;lt;/sql&amp;gt;&lt;br /&gt;
 &amp;lt;/uninstall&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
 &amp;lt;administration&amp;gt;&lt;br /&gt;
  &amp;lt;!-- Administration Menu Section --&amp;gt;&lt;br /&gt;
  &amp;lt;menu&amp;gt;Hello World!&amp;lt;/menu&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;!-- Administration Main File Copy Section --&amp;gt;&lt;br /&gt;
  &amp;lt;files folder=&amp;quot;admin&amp;quot;&amp;gt;&lt;br /&gt;
   &amp;lt;filename&amp;gt;hello.php&amp;lt;/filename&amp;gt;&lt;br /&gt;
   &amp;lt;filename&amp;gt;index.html&amp;lt;/filename&amp;gt;&lt;br /&gt;
   &amp;lt;filename&amp;gt;install.sql&amp;lt;/filename&amp;gt;&lt;br /&gt;
   &amp;lt;filename&amp;gt;uninstall.sql&amp;lt;/filename&amp;gt;&lt;br /&gt;
  &amp;lt;/files&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;/administration&amp;gt;&lt;br /&gt;
&amp;lt;/install&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will notice two attributes present on the &amp;lt;file&amp;gt; tags within the &amp;lt;install&amp;gt; and &amp;lt;uninstall&amp;gt; sections: charset and driver. The charset is the type of charset to use. The only valid charset is utf8. If you want to create install files for non-utf8 databases (for older version of MySQL), you should omit this attribute.&lt;br /&gt;
&lt;br /&gt;
The driver attribute specifies which database the queries were written for. Currently, this can only be mysql, but in future versions of Joomla! there may be more database drivers available.&lt;br /&gt;
&lt;br /&gt;
== Conclusion ==&lt;br /&gt;
&lt;br /&gt;
We now have a component that takes advantage of both the Joomla! MVC framework classes and the JDatabase classes. You are now able to write MVC components that interact with the database and can use the Joomla! installer to create and populate database tables.&lt;br /&gt;
&lt;br /&gt;
== Articles in this Series ==&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 1]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 2 - Adding a Model]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 3 - Using the Database]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 4 - Creating an Administrator Interface]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 5 - Basic Backend Framework]]&lt;br /&gt;
&lt;br /&gt;
[[Developing a Model-View-Controller Component - Part 6 - Adding Backend Actions]]&lt;br /&gt;
&lt;br /&gt;
== Contributors ==&lt;br /&gt;
* staalanden&lt;br /&gt;
&lt;br /&gt;
== Download ==&lt;br /&gt;
&lt;br /&gt;
The component can be downloaded at: [http://joomlacode.org/gf/download/frsrelease/8110/29435/com_hello3_01.zip com_hello3_01]&lt;br /&gt;
&lt;br /&gt;
[[Category:Database]]&lt;br /&gt;
[[Category:Tutorials]]&lt;br /&gt;
[[Category:Component Development]]&lt;/div&gt;</summary>
		<author><name>Jumpy972</name></author>
	</entry>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Adding_JavaScript&amp;diff=65238</id>
		<title>Adding JavaScript</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Adding_JavaScript&amp;diff=65238"/>
		<updated>2012-02-29T13:32:45Z</updated>

		<summary type="html">&lt;p&gt;Jumpy972: /* Adding Javascript Files Using JHTML */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{cookiejar}}&lt;br /&gt;
===Adding Javascript===&lt;br /&gt;
----&lt;br /&gt;
This chunk should describe in detail how to add Javascript to the head of&lt;br /&gt;
a template using the Joomla! 1.5 API calls. It should be aimed at&lt;br /&gt;
people who have only minimal knowledge of PHP, HTML and Javascript.&lt;br /&gt;
[[Category:Templates]]&lt;br /&gt;
[[Category:Modules]]&lt;br /&gt;
[[Category:Components]]&lt;br /&gt;
[[Category:Plugins]]&lt;br /&gt;
[[Category:Tutorials]]&lt;br /&gt;
&lt;br /&gt;
Add the following code to have the Javascript library /media/system/js/sample.js included in your template.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScript( &#039;/media/system/js/sample.js&#039; );&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Explanation==&lt;br /&gt;
Ultimately you are trying to have the resulting HTML page have a Javascript included in the head element (i.e. &amp;lt;head&amp;gt; ... &amp;lt;/head&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;/media/system/js/sample.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Ensure that the Javascript you want to include is in the directory, from the above example:&lt;br /&gt;
   &amp;lt;nowiki&amp;gt;/media/system/js/sample.js&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Load your page into a browser and verify that the &amp;lt;script&amp;gt; tag is in the &amp;lt;head&amp;gt; area and able to load the Javascript. Again, using the example: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;http://www.example.com/media/system/js/sample.js&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When successful the script is integrated into your page. Now you can use Javascript in your HTML.&lt;br /&gt;
&lt;br /&gt;
Do not directly add the &amp;lt;script&amp;gt; to your template&#039;s index.php. The code will insert the &amp;lt;script&amp;gt; line where your index.php has the following line:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;jdoc:include type=&amp;quot;head&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Add this PHP code to your page, in the head, or next to the Javascript code you will use, depending on your preference.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
$document-&amp;gt;addScript( &#039;/media/system/js/sample.js&#039; );&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Reload and view the page. Ensure that the sample.js is included in the &amp;lt;head&amp;gt; section.&lt;br /&gt;
&lt;br /&gt;
== Adding Javascript Files Using JHTML ==&lt;br /&gt;
You may also use the [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html JHTML] [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] method to add a Javascript file to the head of your document.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$filename = &#039;filename.js&#039;;&lt;br /&gt;
// Add the path parameter if the path is different than &#039;media/system/js/&#039;&lt;br /&gt;
$path = &#039;path/to/file/&#039;;&lt;br /&gt;
JHTML::script($filename, $path);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
There is a third Boolean argument that can be passed to the script method. Set this to true if you also want MooTools loaded.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$filename = &#039;filename.js&#039;;&lt;br /&gt;
// Add the path parameter if the path is different than &#039;media/system/js/&#039;&lt;br /&gt;
$path = &#039;path/to/file/&#039;;&lt;br /&gt;
// MooTools will load if it is not already loaded&lt;br /&gt;
JHTML::script($filename, $path, true);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Please Note:&#039;&#039;&#039; Joomla 1.6+ may handle MooTools differently than in previous versions. &amp;lt;ref&amp;gt;[http://forum.joomla.org/viewtopic.php?f=502&amp;amp;t=273960 Whitepaper] Upgrade to mootools 1.2&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jumpy972</name></author>
	</entry>
</feed>