API16

JRegistry/getInstance: Difference between revisions

From Joomla! Documentation

m clean up
m preparing for archive only
 
Line 4: Line 4:




{{subst:Description:JRegistry/getInstance}}
 


===Syntax===
===Syntax===
Line 51: Line 51:




{{subst:SeeAlso:JRegistry/getInstance}}
 


===Examples===
===Examples===
<CodeExamplesForm />
=== Code Examples ===
<dpl>
<dpl>
  noresultsheader=\n
  noresultsheader=\n
  category=getInstance
  category=getInstance
  category=JRegistry
  category=JRegistry
  category=CodeExample
  namespace=CodeExample
  category=MethodExample
  category=MethodExample
  include=*
  include=*
  format= ,,,
  format= ,,,
</dpl>
</dpl>

Latest revision as of 01:59, 25 March 2017

Description

Returns a reference to a global JRegistry object, only creating it if it doesn't already exist.



Syntax

static getInstance($id, $namespace= '_default')
Parameter Name Default Value Description
$id An ID for the registry instance
$namespace '_default' The default namespace for the registry object [optional]

Returns

object The object.

Defined in

libraries/joomla/registry/registry.php

Importing

jimport( 'joomla.registry.registry' );

Source Body

public static function getInstance($id, $namespace = '_default')
{
        static $instances;

        if (!isset ($instances)) {
                $instances = array ();
        }

        if (empty ($instances[$id])) {
                $instances[$id] = new JRegistry($namespace);
        }

        return $instances[$id];
}



Examples

Code Examples