首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

在Magento中运用Collection

2012-10-31 
在Magento中使用Collection1. 对模型对应的表集合进行排序$collection Mage::getModel(module/model_na

在Magento中使用Collection
1. 对模型对应的表集合进行排序

    $collection = Mage::getModel('module/model_name')->getCollection();    $collection->getSelect()->order('last_name ASC');


2. 对多个字段进行排序
      $collection = Mage::getModel('module/model_name')->getCollection();      $collection->getSelect()->order( array('order ASC','last_name ASC', 'first_name ASC') );


3. 使用IF/THEN
      $collection = Mage::getModel('module/model_name')->getCollection();      $collection->getSelect()->order( array('IF(`order`>0, `order`, 9999) ASC','last_name ASC', 'first_name ASC') );


在上面的例子中,如果order大于0并且小于等于9999按照升序排列,然后按last_name, first_name升序排列。

热点排行