public function actionIndex(){ $session = YII::$app->session; //判断session是否开启 if(!$session->isActive) { //未开启,需要开启 $session->open(); } //设置session $session->set('user_name','zhangsan'); //获取session $user_name = $session->get('user_name'); echo $user_name; //删除session $session->remove('user_name'); //数组形式的session //设置session $session['userName'] = 'lisi'; //获取session $user_name = $session['userName']; echo $user_name; //删除session unset($session['userName']); }