Home > PHP Framework > YII > body text

How to set up session in yii

(*-*)浩
Release: 2019-12-04 11:12:33
Original
2843 people have browsed it

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:

How to set up session in yii

## 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',
),
Copy after login

Keep the session in the database settings:

'session' => array (
    'class' => 'system.web.CDbHttpSession',
    'connectionID' => 'db',
    'sessionTableName' => 'actual_table_name',
)
Copy after login

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!

Related labels:
yii
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