一,在Yii中使用session
1,CHttpSession
与原生态php5的session使用差别是,php5使用session_start();$_session['key'] = $value;
在yii中,session已经被封装。
To start the session, call open(); To complete and send out session data, call close(); To destroy the session, call destroy().
If autoStart is set true, the session will be started automatically when the application component is initialized by the application.
Java代码
2,CDbHttpSession
CDbHttpSession继承自 CHttpSession ,把session数据存储在数据库中(表名是YiiSession),
The table name can be changed by setting sessionTableName. If the table does not exist, it will be automatically created if autoCreateSessionTable is set true.
The following is the table structure:
CREATE TABLE YiiSession
(
id CHAR(32) PRIMARY KEY,
expire INTEGER,
data TEXT
)
CDbHttpSession> By default, it will use an SQLite3 database named 'session-YiiVersion.db' under the application runtime directory. You can also specify connectionID so that it makes use of a DB application component to access database.
When using CDbHttpSession in a production server, we recommend you pre-create the session DB table and set autoCreateSessionTable to be false. This will greatly improve the performance. You may also create a DB index for the 'expire' column in the session table to further improve the performance.
Sql代码