Yii operation session instance introduction, yiisession instance. Yii operation session instance introduction, yiisession instance this article describes how to use session in the Yii Framework, the specific steps are as follows: 1. differences with standard php code: In the Yii Framework, introduction to session instances without yii operations, yiisession instances
This article briefly describes how to use session in the Yii Framework. the specific steps are as follows:
I. differences from standard php code:
In the Yii Framework, you do not need to use session_start () like the standard PHP code (),
In the Yii Framework, the autoStart attribute is set to true by default. therefore,
Although session_start () is not used, you can still use the $ _ SESSION global variable, but it is best to use the Yii: app-> session encapsulated by the Yii Framework.
II. 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 in a more complex way
Configuration items can be located inComponents of protected/config/main. phpMedium:
'session'=>array( 'autoStart'=>false(/true), 'sessionName'=>'Site Access', 'cookieMode'=>'only', 'savePath'='/path/to/new/directory',),
Keep the session settings in the database:
'session' => array ( 'class' => 'system.web.CDbHttpSession', 'connectionID' => 'db', 'sessionTableName' => 'actual_table_name',),
In addition, for debugging, you sometimes need to know the session ID of the current user,
The value is in:
Yii::app()->session->sessionID
Finally, when the user logs out, you need to eliminate the trace, you can use:
Yii::app()->session->clear()
Remove all session variables, and then call
Yii::app()->session->destroy()
The session data stored on the server is removed.
How does yii set the session time? You can set help3ks in mainphp or on the page.
You must first. set session timeout in php, 'sessiontimeoutseconds '=> 300, and then in yii: app ()-> user-> setState ('usersessiontimeout', time () + Yii :: app ()-> params ['sessiontimeoutseconds ']); call the page.
Hope to help you
How to configure SESSION in yii
Is it okay to use the session directly?
This article describes how to use session in the Yii Framework. the specific steps are as follows: 1. differences from standard php code: In the Yii Framework, you do not...