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.

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

报告相同问题?

悬赏问题

  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致