Magento: AddAttributeToSort not working

I have a piece of code that uses the getCollection() method to pull out some records:

$banner = Mage::getModel('banner/banner')->getCollection()
            ->addFieldToFilter('status', '1')
            ->addFieldToFilter('banner_group', 'homepage_banner');

This works fine but I want to sort the results by their ‘order’ field (numeric).

So I motified the code to look like this:

$banner = Mage::getModel('banner/banner')->getCollection()
            ->addAttributeToSort('order', 'ASC')
            ->addFieldToFilter('status', '1')
            ->addFieldToFilter('banner_group', 'homepage_banner');

But now it just crashes and I get a blank page.

Anyone any idea what is happening here? Is it because I’m doing addAttribute and not addField like I am to filter?

Thanks,

Billy

2 thoughts on “Magento: AddAttributeToSort not working”

Leave a Reply

Your email address will not be published. Required fields are marked *