W3cubDocs

/Phalcon 2

Class Phalcon\Session\Bag

implements Phalcon\DI\InjectionAwareInterface, Phalcon\Session\BagInterface, IteratorAggregate, Traversable, ArrayAccess, Countable

This component helps to separate session data into “namespaces”. Working by this way you can easily create groups of session variables into the application

$user = new \Phalcon\Session\Bag('user');
$user->name = "Kimbra Johnson";
$user->age = 22;

Methods

public __construct (string $name)

Phalcon\Session\Bag constructor

public setDI (Phalcon\DiInterface $dependencyInjector)

Sets the DependencyInjector container

public Phalcon\DiInterface getDI ()

Returns the DependencyInjector container

public initialize ()

Initializes the session bag. This method must not be called directly, the class calls it when its internal data is accesed

public destroy ()

Destroys the session bag

$user->destroy();

public set (string $property, string $value)

Sets a value in the session bag

$user->set('name', 'Kimbra');

public mixed get (string $property, [string $defaultValue])

Obtains a value from the session bag optionally setting a default value

echo $user->get('name', 'Kimbra');

public boolean has (string $property)

Check whether a property is defined in the internal bag

var_dump($user->has('name'));

public boolean remove (string $property)

Removes a property from the internal bag

$user->remove('name');

public getIterator ()

...

public string __get (string $property)

Magic getter to obtain values from the session bag.

echo $user->name;

public __set (string $property, string $value)

Magic setter to assign values to the session bag. Alias for Phalcon\Session\Bag::set()

$user->name = "Kimbra";

public boolean __isset (string $property)

Magic isset to check whether a property is defined in the bag. Alias for Phalcon\Session\Bag::has()

var_dump(isset($user['name']));

public boolean __unset (string $property)

Magic unset to remove items using the property syntax. Alias for Phalcon\Session\Bag::remove()

unset($user['name']);

public offsetGet (unknown $property)

...

public offsetSet (unknown $property, unknown $value)

...

public offsetExists (unknown $property)

...

public offsetUnset (unknown $property)

...

public count ()

...

© 2011–2016 Phalcon Framework Team
Licensed under the Creative Commons Attribution License 3.0.
https://docs.phalconphp.com/en/2.0.0/api/Phalcon_Session_Bag.html