Documentation

目次

前のトピックへ

< Class Phalcon\Session\Adapter\Files

次のトピックへ

Class Phalcon\Session\Exception >

このページ

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

<?php

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

Destroyes 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 __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 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 string __get (string $property)

Magic getter to obtain values from the session bag. Alias for Phalcon\Session\Bag::get()

<?php

 echo $user->name;

public boolean has (string $property)

Check whether a property is defined in the internal bag

<?php

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

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 remove (string $property)

Removes a property from the internal bag

<?php

 $user->remove('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']);