Zend Framework 中的业务逻辑和数据映射器
我不情愿地为我当前的项目采用了数据映射器方法,但我有点困惑。
商业模式
工人有一个名字、一组工作时间和成本。
数据模型
工人由劳动力类型和工作模式(三个不同的表)组成。工人的成本是根据劳动力类型和工作模式的组合来计算的。
我的问题...
我似乎有两种不同的模型,一种表示业务逻辑,一种表示数据结构。我的理解是我的模型应该代表业务逻辑,但是当我想插入一个新的工作人员时会发生什么?这是使用带有两个下拉菜单的表单来完成的,即工作模式和工作模式。成本,其 id 是业务模型不需要的。
使困惑?我是。
I reluctantly adopted a data mapper approach for my current project but I've been left a little confused.
Business Model
A worker has a name, a set of working hours, and a cost.
Data Model
A worker is made up of a labour type and a working pattern (three different tables). The cost of the worker is calculated based on a combination of the labour type and the working pattern.
My problem...
I seem to have two different models, one that represents business logic and one that represents data structure. I was of the understanding that my model should represent the business logic, but what happens when I want to insert a new worker? This is done using a form with two drop downs, the working pattern & the cost, the id's of which are not needed by the business model.
Confused? I am.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
zend 框架没有真正支持数据模型。但是 weierophinney 确实很好地展示了如何实现它们。另一个非常好的描述是这个。
通常,模型表示数据并包含逻辑。数据模型是一种独立于后端的写入/获取数据的方式。对于模型和应用程序来说,数据来自哪里并不重要。因此,无需接触任何其他内容即可交换数据存储。
There is no real support for data models with the zend framework. But weierophinney does a realy good job to show how they could be implemented. Another very good description is this one.
Usually a model represents the data and includes the logic. The data model is a backend independed way to write/get data. For the model and the application it doesn't matter from where the data comes. Thus the datastorage can be exchanged without having to touch anything else.
Zend Framework (Zend_Db_Table) 中的默认数据建模可能不是面向对象数据建模的最佳选择。
尝试使用像 Doctrine (http://www.doctrine-project.org/) 这样的 ORM,它允许您创建域对象模型并几乎透明地将其存储在数据库中。通过这种方式,您可以将业务模型和数据模型组合在单个类中。
Default data modelling in Zend Framework (Zend_Db_Table) isn't probably the best choice for object oriented data modelling.
Try using ORM like Doctrine (http://www.doctrine-project.org/) it allows you to create domain object model and almost transparently store it in database. This way you can have business model and data model combined in single classes.