旗下导航:搜·么
当前位置:网站首页 > PHP框架 > YII > 正文

yii2 怎样开启session【yii框架教程】,yii2

作者:搜搜PHP网发布时间:2019-12-31分类:YII浏览:116


导读:yii2翻开session(引荐进修:yii教程)useyii\web\Session;$session=Yii::$app->session;//...

yii2翻开session (引荐进修:yii教程)

use  yii\web\Session;
 
$session = Yii::$app->session;
// check if a session is already open
if ($session->isActive) ...
// open a session
$session->open();
// close a session
$session->close();
// destroys all data registered to a session.
$session->destroy();

设置session

$session = Yii::$app->session;
$session->set('user_id', '1234');
//OR
$session['user_id'] = '1234';
//OR
$_SESSION['user_id'] = '1234';

读取session

$session = Yii::$app->session;
$user_id = $session->get('user_id');
//OR
$user_id = $session['user_id'];
//OR
$user_id = isset($_SESSION['user_id']) ? $_SESSION['user_id'] : null;

烧毁session

$session = Yii::$app->session;
$session->remove('user_id');
//OR
unset($session['user_id']);
//OR
unset($_SESSION['user_id']);

以上就是yii2 怎样开启session的细致内容,更多请关注ki4网别的相干文章!

标签:yii2