Home  >  Article  >  PHP Framework  >  How to set up session in yii

How to set up session in yii

(*-*)浩
(*-*)浩Original
2019-12-04 11:12:332844browse

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',
),

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!

Statement:
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