Zendframework Rowset 通过键选择
我试图通过行的主键访问 fetchAll 调用的行(返回 Zend_Db_Table_Rowset_Abstract)。
我想知道除了循环并找到所需的行之外,最简单的方法是什么。
I'm trying to access rows of a fetchAll call (returns Zend_Db_Table_Rowset_Abstract) by a row's primary key.
I was wondering what would be the easiest way of doing this, besides looping through and finding the desired row.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我没记错的话,
Zend_Db_Table_Rowset_Abstract
只是传递了一个数组(或类似数组的东西),然后当您迭代它时,它会创建Zend_Db_Table_Row_Abstract
对象。最好的方法可能是循环一次,并将行存储在数组中,并按主键索引。这样你就可以执行一个循环,然后可以通过该键访问任何行。
更新:刚刚查看了源代码,这是(最终)传递给行集对象的数据:
当您第一次迭代行集时,原始数组用于创建行对象。在此之前数据尚未循环,因此您没有执行已经完成的操作。
所以你必须做这样的事情来将行映射到主键(我有一段时间没有使用 Zend_Db_* ,将其视为伪代码):
当然,你可以扩展抽象行集类并执行如果你愿意的话,可以在内部这样做。
If I recall correctly,
Zend_Db_Table_Rowset_Abstract
is just passed an array (or something that acts like one), then as you iterate through it, it creates theZend_Db_Table_Row_Abstract
objects.The best way may be to loop through once, and store the rows in an array, indexed by the primary key. That way you do one loop, then can access any row by the key.
Update: Just took a look at the source, here's data that's (eventually) passed to the rowset object:
When you iterate through the rowset for the first time, that original array is used to create the row objects. The data hasn't been looped through before that point, so you're not doing something that's already been done.
So you have to do something like this to map rows to primary key (I haven't used
Zend_Db_*
for a while, treat this a pseudocode):Of course you can extend the abstract rowset class and do this internally if you want.
使用 '$db->find($id)->current();'
希望有帮助。
Use '$db->find($id)->current();'
Hope it helps.