如何将 Propel 对象存储到文件中?
我还需要 Propel 可以选择将数据存储到数据库和文件中。有什么办法可以做到这一点吗?我将创建对象,填充数据,然后需要将它们存储到文件(会话)中,并能够稍后重新创建对象。有时它也会进入数据库。有什么想法吗?
I need to have option for Propel to store the data into database and file as well. Is there any way how to do that? I'll create the objects, fill the data and then need to store them into file (session) and be able to recreate the objects later. In some time it will go to database as well. Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您始终可以创建对象,填充一些字段,然后将对象序列化为字符串,然后将其保存到文件中。如果您随后反序列化该字符串,您将获得原始对象。请注意对无法序列化或应在序列化时重新创建的对象或资源的引用。
一旦你在一个类中实现了这一功能,你就可以编写一个行为(在 Propel 1.5 中)将其添加到你的所有模型类中。
I assume you could always create the object, fill some fields, and then serialize the object to a string, which you can save to a file. If you then deserialize this string, you get your original object. Watch out for references to objects or resources that can't be serialized, or should be re-created on serialization.
Once you get this working in one class, you can write a behavior (in Propel 1.5) that adds it to all your model classes.