Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add "Order By" when loading a Magento Model

Tags:

magento

I am trying to load a list of items from a Magento model. What I want to do is get the items in order by their created date so that I have the newest first.

Anyone know how I can do that?

Here is what I have so far:

$model = Mage::getModel('testimonials/testimonials')
  ->getCollection();
like image 467
Josh Pennington Avatar asked Jul 01 '10 13:07

Josh Pennington


2 Answers

I was able to find the answer on my own. This is what I had to do:

$model = Mage::getModel('testimonials/testimonials')
->getCollection()
->setOrder('created_time', 'DESC');
like image 67
Josh Pennington Avatar answered Nov 02 '22 10:11

Josh Pennington


another method that can work too:

$model = Mage::getModel('package/module');

$model->getCollection()
      ->getSelect()->order();
like image 34
mivec Avatar answered Nov 02 '22 12:11

mivec