session; if ($session->isActive)$session->open(); if(strpos($name,'.')!==false) { self::setArray($name,$value); } else{ $session->set($name, $value); } return true; } //读取 public static function get($name) { $session = Yii::$app->session; if ($session->isActive)$session->open(); if(strpos($name,'.')!==false) { return self::getArray($name); } else { return $session->get($name); } } //设置数组中的值,用法 setArray('user.name','jack') public static function setArray($name,$value) { $session = Yii::$app->session; if ($session->isActive)$session->open(); $names = explode('.',$name); $rs = $session->get($names[0]); $rs[$names[1]] = $value; self::set($names[0],$rs); return true; } //读取 public static function getArray($name) { $session = Yii::$app->session; if ($session->isActive)$session->open(); $names = explode('.',$name); return $session[$names[0]][$names[1]]; } //删除 public static function remove($name) { $session = Yii::$app->session; if ($session->isActive)$session->open(); $session->remove($name); return true; } //销毁 public static function destory() { $session = Yii::$app->session; if ($session->isActive)$session->open(); $session->destroy(); return true; } }