This article briefly describes the method of using session in the YII framework, as follows:
One, and the standard PHP code difference:
In the YII framework, you don't need to use session_start () like standard PHP code.
In the YII framework, the AutoStart property is set to True by default, so
Although Session_Start () is not used, you can still use $_session global variables, but it is best to use the yii::app->session of the YII framework package
Second, the use of Session variables:
Set session:
Yii::app ()->session[' var ']= ' value ';
Use session:
Echo Yii::app ()->session[' var '];
Remove session:
Unset (Yii::app ()->session[' var ');
How to configure your session when using a more complex point
The configuration items can be located in the protected/config/main.php components :
' Session ' =>array (
' AutoStart ' =>false (/true),
' sessionname ' => ' Site Access ',
' cookiemode ' = > ' only ',
' savepath ' = '/path/to/new/directory ',
),
To keep the session in the database settings:
' Session ' => Array (
' class ' => ' system.web.CDbHttpSession ', '
connectionid ' => ' db ',
' Sessiontablename ' => ' actual_table_name ',
),
In addition, for debugging purposes, it is sometimes necessary to know the session ID of the current user,
This value is in:
Yii::app ()->session->sessionid
Finally, when the user exits login (logout), you need to remove traces that can be used:
Remove all session variables, and then call the
Remove the session data stored on the server side.