API16

JSessionStorage/getInstance: Difference between revisions

From Joomla! Documentation

Doxiki (talk | contribs)
New page: ===Description=== Returns a session storage handler object, only creating it if it doesn't already exist. <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[[Descrip...
 
m preparing for archive only
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:
Returns a session storage handler object, only creating it if it doesn't already exist.
Returns a session storage handler object, only creating it if it doesn't already exist.


<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JSessionStorage/getInstance|Edit Descripton]]<nowiki>]</nowiki>
</span>


{{Description:JSessionStorage/getInstance}}
 
 


===Syntax===
===Syntax===
Line 66: Line 64:
</source>
</source>


<span class="editsection" style="font-size:76%;">
 
<nowiki>[</nowiki>[[SeeAlso:JSessionStorage/getInstance|Edit See Also]]<nowiki>]</nowiki>
 
</span>
{{SeeAlso:JSessionStorage/getInstance}}


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

Latest revision as of 02:04, 25 March 2017

Description

Returns a session storage handler object, only creating it if it doesn't already exist.



Syntax

static getInstance($name= 'none', $options=array())
Parameter Name Default Value Description
$name 'none' $name The session store to instantiate
$options array()

Returns

database A object

Defined in

libraries/joomla/session/storage.php

Importing

jimport( 'joomla.session.storage' );

Source Body

public static function getInstance($name = 'none', $options = array())
{
        static $instances;

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

        $name = strtolower(JFilterInput::getInstance()->clean($name, 'word'));
        if (empty ($instances[$name]))
        {
                $class = 'JSessionStorage'.ucfirst($name);
                if (!class_exists($class))
                {
                        $path = dirname(__FILE__).DS.'storage'.DS.$name.'.php';
                        if (file_exists($path)) {
                                require_once $path;
                        } else {
                                // No call to JError::raiseError here, as it tries to close the non-existing session
                                jexit('Unable to load session storage class: '.$name);
                        }
                }

                $instances[$name] = new $class($options);
        }

        return $instances[$name];
}



Examples

Code Examples