Home >PHP Framework >YII >How to use yii2 session
Session
The Session of Yii 2 is relatively simple, just operate it directly through \Yii::$app->session
1) Add a session (Recommended learning: yii tutorial)
<?php $session = \Yii::$app->session; $session->set('smister_name' , 'myname'); $session->set('smister_array' ,[1,2,3]); ?>
2) Read a session
<?php $session = \Yii::$app->session; //读取一个Session $session->get('smister_name); ?>
3) Delete Session
<?php $session = \Yii::$app->session; //删除一个session $session->remove(‘smister_name’); //删除所有session $session->removeAll(); ?>
The above is the detailed content of How to use yii2 session. For more information, please follow other related articles on the PHP Chinese website!