API15

JSession/set

From Joomla! Documentation

< API15:JSession
Revision as of 17:17, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description=== Set data into the session store <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton<nowiki>]</nowiki> <...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The "API15" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Set data into the session store

[Edit Descripton]

Template:Description:JSession/set

Syntax[edit]

set($name, $value, $namespace= 'default')
Parameter Name Default Value Description
$name $name Name of a variable
$value $value Value of a variable
$namespace 'default' $namespace Namespace to use, default to 'default'

Returns[edit]

mixed Old value of a variable

Defined in[edit]

libraries/joomla/session/session.php

Importing[edit]

jimport( 'joomla.session.session' );

Source Body[edit]

function set($name, $value, $namespace = 'default')
{
        $namespace = '__'.$namespace; //add prefix to namespace to avoid collisions

        if($this->_state !== 'active') {
                // @TODO :: generated error here
                return null;
        }

        $old = isset($_SESSION[$namespace][$name]) ?  $_SESSION[$namespace][$name] : null;

        if (null === $value) {
                unset($_SESSION[$namespace][$name]);
        } else {
                $_SESSION[$namespace][$name] = $value;
        }

        return $old;
}

[Edit See Also] Template:SeeAlso:JSession/set

Examples[edit]

<CodeExamplesForm />