Home > Backend Development > PHP Tutorial > yii operation session

yii operation session

WBOY
Release: 2016-08-08 09:30:49
Original
1021 people have browsed it

Notes on using session in Yii framework:
First of all, in Yii framework, you don’t need to use session_start() like standard PHP code.
In Yii framework, the autoStart attribute is set to true by default, so,
Although there is no Using session_start(), you can still use the $_SESSION global variable, but it is better to use Yii::app->session:
encapsulated by the Yii framework to set the session variable:
Yii::app()->session[' var']='value';
Use: echo Yii::app()->session['var'];
Remove: unset(Yii::app()->session['var']) ;
For a more complicated use, how to configure your session
The configuration items can be set in the components of protected/config/main.php:
'session'=>array(
'autoStart'=>false(/ true),
'sessionName'=>'Site Access',
'cookieMode'=>'only',
'savePath'='/path/to/new/directory',
),
Keep session in Database settings:
'session' => array (
'class' => 'system.web.CDbHttpSession',
'connectionID' => 'db',
'sessionTableName' => 'actual_table_name',
),
Okay, what else? By the way, for debugging, sometimes you need to know the session ID of the current user,
This value is in Yii::app()->session->sessionID.
The above introduces Yii session operation, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template