是否有使用 Zend 从多个数据库表中获取数据的最佳实践?我想知道而不是最终想要在不久的将来重构我编写的代码。我正在阅读 Zend 文档,它说:
"You can not specify columns from a JOINed tabled to be returned in a row/rowset. Doing so will trigger a PHP error. This was done to ensure the integrity of the Zend_Db_Table is retained. i.e. A Zend_Db_Table_Row should only reference columns derived from its parent table."
我假设我因此需要使用多个模型——对吗?例如,如果我想获取日期介于两个日期之间的特定用户 ID 的所有订单,我会怎么做?
我知道可以从 Controller 访问两个不同的模型,然后在操作中组合它们各自的数据,但我不会很高兴这样做,因为我一直在阅读 survivalthedeepend.com 和 it tells me that I shouldn't do this ...
在哪里、为什么以及如何? :)
谢谢!
最佳答案
如果您正在阅读 ZFSTDE,在第 9 章(http://www.survivethedeepend.com/zendframeworkbook/en/1.0/implementing.the.domain.model.entries.and.authors)中,这个问题是通过使用数据映射器解决的。
此外,您可以连接 2 个表,只需确保首先调用选择对象的 setIntegrityCheck(false)
方法。文档说一行应该引用父表,但这并不意味着它不能:)
关于php - 使用 Zend 框架时从多个表中获取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3578102/