Zend 框架中的自定义类
我正在使用 Zend Framework 和 Propel。使用 Propel 对象作为存储在数据库中的事物的模型非常容易,但如何创建自定义模型,例如使用 propel 对象的购物车?
我正在考虑创建一个名为 CartItem 和 Cart 的类。如果 CartItem 包含一个 propel Product 类,并且 Cart 包含一个 CartItem 数组,那么在会话中存储这似乎非常昂贵。通常我只使用数组,但我试图通过 OOP 变得更好
I'm using Zend Framework with Propel. It's easy enough to use Propel objects as my models for things that are stored in the database, but how do I go about creating a custom model such as a shopping cart that uses propel objects?
I'm thinking of creating a class called CartItem and Cart. If CartItem contains a propel Product class, and Cart contains an array of CartItems, this seems very expensive to store in a session. Normally I'd just use an array, but I'm trying to get better with OOP
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 PHP 的可序列化接口:http://php.net/manual/de/class。 您可以使用它将
购物车的实例转换为更有效的值(您定义,到底存储什么),在您的情况下是一个二维数组。
尝试这样的操作:
然后使用序列化将购物车存储在会话中并检索它:
祝您的项目好运!
You could use PHP's Interface Serializable: http://php.net/manual/de/class.serializable.php
You can use it to convert an instance of your cart into a more efficient value (you define, what exactly is stored), which is in your case a two-dimensional array.
Try something like this:
Then use serialize to store the cart in the session and retrieve it:
Good Luck with your Project!