Class Phalcon\Session\Bag

implements Phalcon\Di\InjectionAwareInterface, Phalcon\Session\BagInterface

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

  1. <?php
  2. $user = new \Phalcon\Session\Bag('user');
  3. $user->name = "Kimbra Johnson";
  4. $user->age = 22;

Methods

public __construct (unknown $name)

Phalcon\Session\Bag constructor

public setDI (unknown $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 ()

Destroyes the session bag

  1. <?php
  2. $user->destroy();

public set (unknown $property, unknown $value)

Sets a value in the session bag

  1. <?php
  2. $user->set('name', 'Kimbra');

public __set (unknown $property, unknown $value)

Magic setter to assign values to the session bag

  1. <?php
  2. $user->name = "Kimbra";

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

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

  1. <?php
  2. echo $user->get('name', 'Kimbra');

public mixed __get (unknown $property)

Magic getter to obtain values from the session bag

  1. <?php
  2. echo $user->name;

public boolean has (unknown $property)

Check whether a property is defined in the internal bag

  1. <?php
  2. var_dump($user->has('name'));

public boolean __isset (unknown $property)

Magic isset to check whether a property is defined in the bag

  1. <?php
  2. var_dump(isset($user['name']));

public boolean remove (unknown $property)

Removes a property from the internal bag

  1. <?php
  2. $user->remove('name');

public boolean __unset (unknown $property)

Magic unset to remove items using the array syntax

  1. <?php
  2. unset($user['name']);