Documentation

Class Phalcon\Session\Bag

extends abstract class Phalcon\Di\Injectable

implements Phalcon\Events\EventsAwareInterface, Phalcon\Di\InjectionAwareInterface, Phalcon\Session\BagInterface, IteratorAggregate, Traversable, ArrayAccess, Countable

Source on GitHub

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

<?php

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

Methods

public __construct (string $name)

Phalcon\Session\Bag constructor

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

<?php

 $user->destroy();

public set (string $property, string $value)

Sets a value in the session bag

<?php

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

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

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

<?php

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

public boolean has (string $property)

Check whether a property is defined in the internal bag

<?php

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

public boolean remove (string $property)

Removes a property from the internal bag

<?php

 $user->remove('name');

public getIterator ()

...

public string __get (string $property)

Magic getter to obtain values from the session bag.

<?php

 echo $user->name;

public __set (string $property, string $value)

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

<?php

 $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()

<?php

 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()

<?php

 unset($user['name']);

public offsetGet (unknown $property)

...

public offsetSet (unknown $property, unknown $value)

...

public offsetExists (unknown $property)

...

public offsetUnset (unknown $property)

...

public count ()

...

public setDI (Phalcon\DiInterface $dependencyInjector) inherited from Phalcon\Di\Injectable

Sets the dependency injector

public Phalcon\DiInterface getDI ([unknown $error], [unknown $notUseDefault]) inherited from Phalcon\Di\Injectable

Returns the internal dependency injector

public setEventsManager (Phalcon\Events\ManagerInterface $eventsManager) inherited from Phalcon\Di\Injectable

Sets the event manager

public Phalcon\Events\ManagerInterface getEventsManager () inherited from Phalcon\Di\Injectable

Returns the internal event manager

public boolean fireEvent (string $eventName, [mixed $data], [unknown $cancelable]) inherited from Phalcon\Di\Injectable

Fires an event, implicitly calls behaviors and listeners in the events manager are notified

public mixed fireEventCancel (string $eventName, [mixed $data], [unknown $cancelable]) inherited from Phalcon\Di\Injectable

Fires an event, can stop the event by returning to the false

public boolean hasService (string $name) inherited from Phalcon\Di\Injectable

Check whether the DI contains a service by a name

public Phalcon\Di\ServiceInterface setService (unknown $name) inherited from Phalcon\Di\Injectable

Sets a service from the DI

public object|null getService (unknown $name) inherited from Phalcon\Di\Injectable

Obtains a service from the DI

public mixed getResolveService (string $name, [array $args], [unknown $noerror], [unknown $noshared]) inherited from Phalcon\Di\Injectable

Resolves the service based on its configuration

public attachEvent (string $eventType, Closure $callback) inherited from Phalcon\Di\Injectable

Attach a listener to the events

public __sleep () inherited from Phalcon\Di\Injectable

...

public __debugInfo () inherited from Phalcon\Di\Injectable

...