Ger*_*rep 3 php session object codeigniter-2
我正在使用CI,我有一个UserModel,它根据登录信息选择用户并设置userVO并在这样的会话中添加此userVO:
$this->session->set_userdata('user', $userVO);
Run Code Online (Sandbox Code Playgroud)
当我尝试访问此会话时,它返回此错误:
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.
Run Code Online (Sandbox Code Playgroud)
我找到了一个"解决方案",我需要CI在会话类之前加载UserVO类并且它可以工作.
问题是我有很多os VO类,我会在会话中需要它们,并且自动加载它们是一件坏事,因为我不会同时需要它们.
有没有解决方法?
在此先感谢您的帮助.
Bre*_*ley 16
发生的事情是您正在将类的实例保存到会话中.为了恢复它,首先需要加载它是实例的基类.你可能有很多VO类的"实例",而不是很多VO类.您只需要加载具有类声明的文件.
类实例实际上只包含从基类更改的内容,而不是整个类.所以它需要底层的类来知道"默认值"是什么.