教义2:实体可以保存到会话中吗? [英] Doctrine 2: Can entities be saved into sessions?

查看:108
本文介绍了教义2:实体可以保存到会话中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将实体保存到PHP会话后遇到懒惰加载问题。有没有解决办法?

解决方案

请参阅序列化实体在原则手册中:(您在会话中保存的所有内容都是序列化和反序列化的)。


序列化实体可能是有问题的,并不是真正的推荐,至少不是一个实体实例仍然保留对代理对象的引用,或者仍然由EntityManager管理。


有一个技术限制,可以避免私有属性在实体代理时被序列化(惰性加载的实体被代理)。



这意味着您必须避免为要序列化的实体使用 private 属性(使用 protected 实体代替)。



另外,如果一个惰性加载的实体在序列化时没有加载,那么在d E-系列化。所以你必须在序列化之前确保实体是完全加载的。


I'm having a problem with lazy loading after I save an entity into a PHP session. Is there any workaround for this?

解决方案

See Serializing Entities in doctrine manual: (Everything you save in a session is serialized and deserialized.)

Serializing entities can be problematic and is not really recommended, at least not as long as an entity instance still holds references to proxy objects or is still managed by an EntityManager.

There is a technical limitation that avoid private properties from being serialized when an entity is proxied (lazy-loaded entities are proxied).

This means that you have to avoid using private properties for the entities you want to serialize (use protected entities instead).

Also, if a lazy-loaded entity is not loaded at serialization time, it won't be loadable after de-serialization. So you have to make sure the entity is fully loaded before serializing it.

这篇关于教义2:实体可以保存到会话中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆