Home > Article > PHP Framework > How to set up session in yii
First of all, in the Yii framework, you do not need to use session_start() like standard PHP code. In the Yii framework, the autoStart attribute is set to true by default, so even if session_start() is not used, you can still use $_SESSION global variable, but it is best to use Yii::app->session:
## encapsulated by the Yii framework to set the session variable: Yii:: app()->session['var']='value'; (Recommended learning: yii framework)
Use: echo Yii::app( )->session['var']; Remove: unset(Yii::app()->session['var']);
How to use it more complicatedly Configure your session 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 the session in the database settings:
'session' => array ( 'class' => 'system.web.CDbHttpSession', 'connectionID' => 'db', 'sessionTableName' => 'actual_table_name', )
The above is the detailed content of How to set up session in yii. For more information, please follow other related articles on the PHP Chinese website!