PHP Класс yii\mongodb\Session

By default, Session stores session data in a collection named 'session' inside the default database. This collection is better to be pre-created with fields 'id' and 'expire' indexed. The collection name can be changed by setting [[sessionCollection]]. The following example shows how you can configure the application to use Session: Add the following to your application config under components: php 'session' => [ 'class' => 'yii\mongodb\Session', 'db' => 'mymongodb', 'sessionCollection' => 'my_session', ] Session extends [[MultiFieldSession]], thus it allows saving extra fields into the [[sessionCollection]]. Refer to [[MultiFieldSession]] for more details. Tip: you can use MongoDB TTL index for the session garbage collection for performance saving, in this case you should set [[Session::gCProbability]] to 0.
С версии: 2.0
Автор: Paul Klimov ([email protected])
Наследование: extends yii\web\MultiFieldSession
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$db the MongoDB connection object or the application component ID of the MongoDB connection. After the Session object is created, if you want to change this property, you should only assign it with a MongoDB connection object. Starting from version 2.0.2, this can also be a configuration array for creating the object.
$sessionCollection the name of the MongoDB collection that stores the session data. Please refer to [[Connection::getCollection()]] on how to specify this parameter. This collection is better to be pre-created with fields 'id' and 'expire' indexed.

Открытые методы

Метод Описание
destroySession ( string $id ) : boolean Session destroy handler.
gcSession ( integer $maxLifetime ) : boolean Session GC (garbage collection) handler.
init ( ) Initializes the Session component.
readSession ( string $id ) : string Session read handler.
regenerateID ( boolean $deleteOldSession = false ) Updates the current session ID with a newly generated one.
writeSession ( string $id, string $data ) : boolean Session write handler.

Описание методов

destroySession() публичный Метод

Do not call this method directly.
public destroySession ( string $id ) : boolean
$id string session ID
Результат boolean whether session is destroyed successfully

gcSession() публичный Метод

Do not call this method directly.
public gcSession ( integer $maxLifetime ) : boolean
$maxLifetime integer the number of seconds after which data will be seen as 'garbage' and cleaned up.
Результат boolean whether session is GCed successfully

init() публичный Метод

This method will initialize the [[db]] property to make sure it refers to a valid MongoDB connection.
public init ( )

readSession() публичный Метод

Do not call this method directly.
public readSession ( string $id ) : string
$id string session ID
Результат string the session data

regenerateID() публичный Метод

Please refer to for more details.
public regenerateID ( boolean $deleteOldSession = false )
$deleteOldSession boolean Whether to delete the old associated session file or not.

writeSession() публичный Метод

Do not call this method directly.
public writeSession ( string $id, string $data ) : boolean
$id string session ID
$data string session data
Результат boolean whether session write is successful

Описание свойств

$db публичное свойство

the MongoDB connection object or the application component ID of the MongoDB connection. After the Session object is created, if you want to change this property, you should only assign it with a MongoDB connection object. Starting from version 2.0.2, this can also be a configuration array for creating the object.
public $db

$sessionCollection публичное свойство

the name of the MongoDB collection that stores the session data. Please refer to [[Connection::getCollection()]] on how to specify this parameter. This collection is better to be pre-created with fields 'id' and 'expire' indexed.
public $sessionCollection