doufeng9567 2014-01-09 23:01
浏览 56
已采纳

如何排序Varien_Data_Collection的通用实例

In Magento, the Varien_Data_Collection class makes provisions for sorting, but it ultimately leaves the work up to the extending class (usually Varien_Data_Collection_Db) through the load method.

But has anyone already done the work to make a generic instance of Varien_Data_Collection sortable?

By that I mean using some crafty means of PHP's user-sorting functions. Not that I'm lazy, but it seems to be a lot of work to re-invent the wheel if it already exists.

Does anyone have a solution for this?

  • 写回答

1条回答 默认 最新

  • dongrong8972 2014-01-10 00:23
    关注

    The class Varien_Data_Collection_Filesystem has some example code for using usort to sort files and directories. If you have a custom collection class which extends Varien_Data_Collection you could implement your own sort functions very much like the filesytem class does. It applies the sort on the collection load method which ultimately has a callback function to usort using a specified sort order ($collection->setOrder('sort_attribute')). As far as I am aware there are no existing methods to do this, mainly because magento does most sorting on db data which can be achieved through the sql which is much better for performance.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面