我并不是说所有模型都是表格。
我想问的是,在使用 Zend 时是否每个表都必须有自己的专门定义的类?有什么办法可以摆脱这种笨拙的样板编码。我们刚刚开始研究 Zend(希望离开程序化 PHP 领域!),我的同事认为这最终可能会非常耗时。
这是人们使用 ORM 解决方案的原因吗?还有其他解决办法吗?
感谢您的回复。
最佳答案
Zend Table 类遵循 Table Data Gateway模式,根据定义
... holds all the SQL for accessing a single table or view: selects, inserts, updates, and deletes. Other code calls its methods for all interaction with the database.
In the book , Fowler对此并没有那么死板,说
for very simple cases, you can have a single TDG that handles all methods for all tables. You can even have one for views or even for interesting queries that aren't kept in the database as views.
但是,除了能够使用 View 之外,Zend_Db_Table
不适应这一点。您可以创建对多个表的查询,但这些查询必须直接通过 Zend_Db_Adapter
进行,或者 - 在使用连接时 - 通过关闭完整性检查来进行。否则,您必须使用 Zend_Db_Table Relationships
所以是的,一个实例应该对应一个表或 View 。如果您不打算扩展类,则不需要为此创建类。 Zend_Db_Table_Definitions
允许您动态配置 Zend_Db_Table
实例。
请注意,TDG 是一种数据源架构模式,而不是对象关系模式。它的目的不是帮助 impedance-mismatch ,但将数据库访问代码与业务逻辑分开。
关于php - Zend 中的每个表都必须映射到它自己的类吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3586239/