我将各种设置存储在类的对象中,然后在会话中保存该设置,因为我需要在后续的ajax调用中使用此设置。
大多数时候(我会说90%),它运行正常,但很多时候它不会在会话中存储设置而且ajax调用失败。
这是我的班级代码
Class PDOSoup {
private $tableName;
private $columns;
private $currentpage;
private $limit;
private $objKey;
public function __construct() {
$this->objKey = $this->getRandomKey();
}
public function setTableName($param) {
$tableName = $param;
}
public function setCurrentPage($param) {
$currentpage = $param;
}
public function setLimit($param) {
$limit = $param;
}
public function saveObject() {
$_SESSION[$this->objKey] = serialize($this);
}
}
这是我的ajax电话
//this key is stored in the input type hidden to access object again
$instanceKey = $_REQUEST["object_key"];
$obj = unserialize($_SESSION[$instanceKey]);//here it gives error sometimes
//now call method of class
$obj->someothermethod();
这个$ obj-> someothermethod();大部分时间都有效,但有时却失败了 在会话线上给出错误
Notice: Undefined index: !KpcZ6nkAr in
有人可以解释为什么有时它不起作用?或者有更好的方法 做同样的事情?