将会话变量与对象一起使用
我创建了一个对象并分配了如下值:
$car_object =&新车();
$car_object->offer = 'Sale';
$car_object->type = 'Sport Car';
$car_object->location = "Buffalo, New york";
如何将 $car_object 存储在会话变量中? 如何从会话变量中获取 $car_object ?
I have created an object and assigned values as follows:
$car_object =& new Car();
$car_object->offer = 'Sale';
$car_object->type = 'Sport Car';
$car_object->location = "Buffalo, New york";
How can I store the $car_object inside a session variable?
How can I get the $car_object out from the session variable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
设置为会话:
从会话获取:
Set to session:
Get from session:
一个更简单的方法是:
然后你可以使用这样的东西;
这有助于建立一个更易于管理的框架来在会话中存储对象。
例如:
A more simpler way would be to do:
Then you can use something like this;
this helps for a more manageable framework for storing objects in the session.
for example:
序列化对象并将其存储到会话中是可行的。以下是关于此问题的完整讨论: PHP:在 $_SESSION 中存储“对象”
Serializing the object and storing it into session works. Here is an entire discussion about this: PHP: Storing 'objects' inside the $_SESSION