按某些字段排序的迭代学说集合
我需要这样的东西:
$products = Products::getTable()->find(274);
foreach ($products->Categories->orderBy('title') as $category)
{
echo "{$category->title}<br />";
}
我知道这是不可能的,但是......我怎样才能在不创建 Doctrine_Query 的情况下做这样的事情?
谢谢。
I need something like this:
$products = Products::getTable()->find(274);
foreach ($products->Categories->orderBy('title') as $category)
{
echo "{$category->title}<br />";
}
I know is it not possible, but... How can I do something like this without creating a Doctrine_Query?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您还可以执行以下操作:
在架构文件中,它看起来像:
You can also do:
In your schema file it looks like:
我只是在看同样的问题。您需要将 Doctrine_Collection 转换为数组:
然后您可以创建一个自定义排序函数并调用它:
其中compareChildren 看起来像:
I was just looking at the same problem. You need to convert the Doctrine_Collection into an array:
Then you can create a custom sort function and call it:
Where compareChildren looks something like:
您可以使用集合迭代器:
如果您想使用 __toString 方法对集合进行排序,会更容易:
You could use collection iterator:
If you want to sort collection using __toString method, it will be much easier:
您可以向 Colletion.php 添加排序函数:
按用户年龄对 Doctrine_Collection 进行排序,如下所示:
You might add a sort function to Colletion.php :
Sorting a Doctrine_Collection of users by their age would look like this: