JDocument/getInstance
From Joomla! Documentation
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.
