Zend Framework:count() 使用 findManyToManyRowset(...) 在空结果上返回 1
在开发小型商店应用程序时,我使用 Zend Framework 的“findManyToManyRowset”功能获取文章的所有颜色。
示例:
$colors = $article->findManyToManyRowset('Shop_Colors',
'Shop_ArticlesToColors');
有些文章没有指定颜色。我使用 count($colors) 对“findManyToManyRowset”的结果进行测试。但我得到的结果不是预期的“0”,而是“1”,这让我很困惑。
这是为什么 ?如果结果为空,我该如何测试?
谢谢 :) 斯蒂芬
While working on a small shop application i fetch all colors of an article using Zend Framework's "findManyToManyRowset" functionality.
Example:
$colors = $article->findManyToManyRowset('Shop_Colors',
'Shop_ArticlesToColors');
Some of the articles don't have and colors assigned. I test it using count($colors) on the result of "findManyToManyRowset". But instead of the expected result "0" i get an "1" as a result, which confuses me.
Why is that ? And how can i test, if an result is empty instead ?
Thank you :)
Stephan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
findManyToManyRowset 返回 Zend_DbTable_Rowset 类的对象。因此 count($colors) 将不会返回行数。
获取行数的方法是:
The findManyToManyRowset returns an object of class Zend_DbTable_Rowset. Therefore count($colors) will not return the number of rows.
The way to get the row count is:
由于计数为 1,您是否转储了 $colors 行集以查看行集中的内容?显然里面有东西。
Since the count is 1, have you dumped out that $colors rowset to see what's in the rowset? Evidently something is in it.
是的,我就是这么做的。受保护的数组 _data 为空。这就是为什么我很困惑:)
但是当你写这篇文章时,我想到了一些事情。我更改了颜色的行集类中的方法“toArray”以满足我的需求(更改了数据的格式)。也许这就是问题所在?
yes, i did that. The protected array _data was empty. That's why i'm confused :)
But as you're writing this, something comes to my mind. I changed the methode "toArray" in the color's rowset class to fit my needs (changed formatting of the data). Maybe that is the problem ?