Actions

Difference between revisions of "JDocument/getInstance"

From Joomla! Documentation

(New page: Returns a document object of a type that is dependent on the document type. Only one object with the particular combination of type and attributes is created (see [http://en.wikipedia.org...)
 
m (See also: Framework => Platform)
 
Line 69: Line 69:
 
It is important to realise that subsequent calls to getInstance with the same type and the same attributes will return the same object instance.
 
It is important to realise that subsequent calls to getInstance with the same type and the same attributes will return the same object instance.
 
===See also===
 
===See also===
* [http://api.joomla.org/Joomla-Framework/Document/JDocument.html#addScript JDocument->addScript on api.joomla.org]
+
* [http://api.joomla.org/Joomla-Platform/Document/JDocument.html#addScript JDocument->addScript on api.joomla.org]
 
<noinclude>[[Category:Development]][[Category:Framework]][[Category:JDocument]]</noinclude>
 
<noinclude>[[Category:Development]][[Category:Framework]][[Category:JDocument]]</noinclude>

Latest revision as of 03:26, 25 September 2013

Returns a document object of a type that is dependent on the document type. Only one object with the particular combination of type and attributes is created (see Singleton pattern). This is a public static method. The actual constructor should be considered private so that all object instantiation must be done using this method.

Syntax

object &getInstance( $type, $attributes )

where:

Argument Data type Description Default
$type string Document type. 'html'
$attributes array Array of attributes to be passed to the class constructor.

The attributes used by the class constructor are:

Attribute Description Default
base Document base URI.
charset Document character set encoding. 'utf-8'
direction Document language reading direction. Default is 'ltr' indicating left-to-right. Use 'rtl' for right-to-left. 'ltr'
language Document language tag. 'en-GB'
lineend Document line end style. \12
link Document URL.
tab String used to indent HTML. \11

Example

To get an object of type 'mytype' with a given set of attributes, you could use:

$attributes = array (
  'charset'     => 'utf-8',
  'lineend'     => 'unix',
  'tab'         => '  ',
  'language'    => 'en-GB',
  'direction'   => 'ltr'
);
$doc = & JDocument::getInstance( 'mytype', $attributes );

It is important to realise that subsequent calls to getInstance with the same type and the same attributes will return the same object instance.

See also