php - 使用 Zend 框架时从多个表中获取数据?

标签 php zend-framework zend-db-table

是否有使用 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/

相关文章:

javascript - 使用 onKeyUp 时禁用 javascript 中的箭头键

php - 是否可以将Laravel 5.5.40降级到5.5.20?

php - 在 zend 框架 2 中不是空条件

zend-framework - 在 Zend 中执行操作后获取所有参数?

php - 方法语法 "public function direct(){}"在 PHP 中如何工作?

php - 切换表时出现 zend db 错误可捕获的 fatal error : Argument 1 passed to __construct() must be an array, 给定对象,调用

php - Zend 框架——我为什么要使用数据映射器/Db_Table_Row?

php从mysql返回值2次

php - 如何用 php 打印 $

mysql - Zend Framework 和 Mysql - 非常慢