Actions

API17

Difference between revisions of "JHtml::"

From Joomla! Documentation

(3 intermediate revisions by one user not shown)
Line 9: Line 9:
  
 
JHtml::_() expects its first parameter to be a string of period-separated values representing a class prefix (optional), a file name, and a method, in that order. When only a filename and method are provided, as seen in the first example below, the prefix defaults to "JHtml" and the resolved class name will consist of "JHtml<filename>." The filename segment of $key is used to find the file in which the class and method are defined among whatever include paths have been attached to the static JHtml class using [[JHtml::addIncludePath/11.1|JHtml::addIncludePath]]. The "/libraries/joomla/html/html" folder is attached to the JHtml class by default when "/libraries/joomla/html/html.php" is included, but other paths can be added, making the functionality of _ extensible.
 
JHtml::_() expects its first parameter to be a string of period-separated values representing a class prefix (optional), a file name, and a method, in that order. When only a filename and method are provided, as seen in the first example below, the prefix defaults to "JHtml" and the resolved class name will consist of "JHtml<filename>." The filename segment of $key is used to find the file in which the class and method are defined among whatever include paths have been attached to the static JHtml class using [[JHtml::addIncludePath/11.1|JHtml::addIncludePath]]. The "/libraries/joomla/html/html" folder is attached to the JHtml class by default when "/libraries/joomla/html/html.php" is included, but other paths can be added, making the functionality of _ extensible.
 
==== Caching ====
 
 
Adding many include paths to JHtml::_ could negatively impact its performance, since it has to search through each of those paths in order to find the method that matches the $key string. However, once a particular key has been used to invoke a function, that key and its corresponding [1] array are cached. As a result, any future calls using that key will execute much faster.
 
  
 
'''Example 1:'''
 
'''Example 1:'''
Line 22: Line 18:
 
'''Example 2:'''
 
'''Example 2:'''
 
<source lang="php">
 
<source lang="php">
echo JHtml::_('myExtension.button.push');
+
echo JHtml::_('myExtension.button.submit');
 
</source>
 
</source>
The above code will output the return value of a static method, myExtensionButton::push(), which should be defined in a file called "button.php," provided that this file exists in the default include path.
+
The above code will output the return value of a static method, myExtensionButton::submit, which should be defined in a file called "button.php," provided that this file exists in the default include path.
  
 
====Additional Parameters ====
 
====Additional Parameters ====
  
 
Any additinal parameters passed to JHtml::_() will be passed as parameters themselves to the resolved method.
 
Any additinal parameters passed to JHtml::_() will be passed as parameters themselves to the resolved method.
 +
 +
==== Caching ====
 +
 +
Adding many include paths to JHtml::_ could negatively impact its performance, since it has to search through each of those paths in order to find the method that matches the $key string. However, once a particular key has been used to invoke a method, that key and its corresponding [http://php.net/manual/en/language.types.callable.php callable] array are cached. As a result, any future calls using that key will execute much faster.
  
 
{{Description:JHtml::_}}
 
{{Description:JHtml::_}}
Line 118: Line 118:
 
** [[JHtmlAccess::usergroup/11.1|JHtmlAccess::usergroup]]
 
** [[JHtmlAccess::usergroup/11.1|JHtmlAccess::usergroup]]
 
** [[JHtmlList::users/11.1|JHtmlList::users]]
 
** [[JHtmlList::users/11.1|JHtmlList::users]]
 +
 
===See also===
 
===See also===
 
* {{JVer|11.1}} '''JHtml::_ source code''' on [[jplatform:html/html.php#cl-69|BitBucket]]
 
* {{JVer|11.1}} '''JHtml::_ source code''' on [[jplatform:html/html.php#cl-69|BitBucket]]

Revision as of 11:17, 14 March 2013

Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Joomla 11.1 JHtml::_

Description

A class loader method.

The _ method of JHtml is a static function that grants quick access to a number of other static methods in the Joomla! platform's HTML subpackage, in particular those classes with the JHtml prefix (i.e. JHtmlBehavior, JHtmlGrid). The return value of this function depends on the return value of the method resolved by parsing the first parameter.

The $key Paremeter

JHtml::_() expects its first parameter to be a string of period-separated values representing a class prefix (optional), a file name, and a method, in that order. When only a filename and method are provided, as seen in the first example below, the prefix defaults to "JHtml" and the resolved class name will consist of "JHtml<filename>." The filename segment of $key is used to find the file in which the class and method are defined among whatever include paths have been attached to the static JHtml class using JHtml::addIncludePath. The "/libraries/joomla/html/html" folder is attached to the JHtml class by default when "/libraries/joomla/html/html.php" is included, but other paths can be added, making the functionality of _ extensible.

Example 1:

echo JHtml::_('form.token');

The above code will output the return value of JHtmlForm::token, found in "/libraries/joomla/html/html/form.php," (which happens to be a hidden form element containing an anti-spoofing token.)

Example 2:

echo JHtml::_('myExtension.button.submit');

The above code will output the return value of a static method, myExtensionButton::submit, which should be defined in a file called "button.php," provided that this file exists in the default include path.

Additional Parameters

Any additinal parameters passed to JHtml::_() will be passed as parameters themselves to the resolved method.

Caching

Adding many include paths to JHtml::_ could negatively impact its performance, since it has to search through each of those paths in order to find the method that matches the $key string. However, once a particular key has been used to invoke a method, that key and its corresponding callable array are cached. As a result, any future calls using that key will execute much faster.

Description:JHtml:: [Edit Descripton]

public static function _ ($key)
Parameter Type Default Description
$key

See also

SeeAlso:JHtml:: [Edit See Also]

User contributed notes

<CodeExamplesForm />