PHP 클래스 yii\web\DbSession

By default, DbSession stores session data in a DB table named 'session'. This table must be pre-created. The table name can be changed by setting [[sessionTable]]. The following example shows how you can configure the application to use DbSession: Add the following to your application config under components: php 'session' => [ 'class' => 'yii\web\DbSession', 'db' => 'mydb', 'sessionTable' => 'my_session', ] DbSession extends MultiFieldSession, thus it allows saving extra fields into the [[sessionTable]]. Refer to MultiFieldSession for more details.
부터: 2.0
저자: Qiang Xue ([email protected])
상속: extends MultiFieldSession
파일 보기 프로젝트 열기: yiisoft/yii2 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$db the DB connection object or the application component ID of the DB connection. After the DbSession object is created, if you want to change this property, you should only assign it with a DB connection object. Starting from version 2.0.2, this can also be a configuration array for creating the object.
$sessionTable the name of the DB table that stores the session data. The table should be pre-created as follows: sql CREATE TABLE session ( id CHAR(40) NOT NULL PRIMARY KEY, expire INTEGER, data BLOB ) where 'BLOB' refers to the BLOB-type of your preferred DBMS. Below are the BLOB type that can be used for some popular DBMS: - MySQL: LONGBLOB - PostgreSQL: BYTEA - MSSQL: BLOB When using DbSession in a production server, we recommend you create a DB index for the 'expire' column in the session table to improve the performance. Note that according to the php.ini setting of session.hash_function, you may need to adjust the length of the id column. For example, if session.hash_function=sha256, you should use length 64 instead of 40.

공개 메소드들

메소드 설명
destroySession ( string $id ) : boolean Session destroy handler.
gcSession ( integer $maxLifetime ) : boolean Session GC (garbage collection) handler.
init ( ) Initializes the DbSession 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 DB 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 DB connection object or the application component ID of the DB connection. After the DbSession object is created, if you want to change this property, you should only assign it with a DB connection object. Starting from version 2.0.2, this can also be a configuration array for creating the object.
public $db

$sessionTable 공개적으로 프로퍼티

the name of the DB table that stores the session data. The table should be pre-created as follows: sql CREATE TABLE session ( id CHAR(40) NOT NULL PRIMARY KEY, expire INTEGER, data BLOB ) where 'BLOB' refers to the BLOB-type of your preferred DBMS. Below are the BLOB type that can be used for some popular DBMS: - MySQL: LONGBLOB - PostgreSQL: BYTEA - MSSQL: BLOB When using DbSession in a production server, we recommend you create a DB index for the 'expire' column in the session table to improve the performance. Note that according to the php.ini setting of session.hash_function, you may need to adjust the length of the id column. For example, if session.hash_function=sha256, you should use length 64 instead of 40.
public $sessionTable