我使用的是CI,我有一个UserModel,它根据登录信息选择用户,并设置一个userVO,然后在这样的会话中添加这个userVO:
$this->session->set_userdata('user', $userVO);
当我尝试访问此会话时,它会返回此错误:
Message: main() [function.main]: The script tried to execute a method
or access a property of an incomplete object. Please ensure that the
class definition "UserVO" of the object you are trying to operate on
was loaded _before_ unserialize() gets called or provide a __autoload()
function to load the class definition.
我找到了一个"解决方案",我需要CI在会话类之前加载UserVO类,它可以工作。
问题是,我有很多os VO类,我需要在会话中使用它们,自动加载它们是件坏事,因为我不需要同时使用它们。
有什么变通办法吗?
提前感谢您的帮助。
发生的事情是将类的实例保存到会话中。为了恢复它,您首先需要加载它作为实例的基类。您可能有很多VO类的"实例",而不是很多VO类。您只需要加载具有类声明的文件。
类实例实际上只包含基类的变化,而不是整个类。因此,它需要底层类知道什么是"默认值"。
我假设$userVO
是模型
$this->session->set_userdata('user', $userVO);
使用
$this->session->set_userdata('user', json_encode($userVO));