读书人

在Magento中运用Collection

发布时间: 2012-10-31 14:37:32 作者: rapoo

在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升序排列。

读书人网 >编程

热点推荐