addFiledToFilter Condition In Magento

As I already mentioned on the previous post that we only can give the condition of attribute name to filter the result. There is another method to filter result that you can use in your customer Module. Let you are having a customer module which is responsible to show some banner on the homepage. For that let you have some place to upload image and also have feature to give sort order and enable disable feature. Here in the below code I will show how to filter the result with addFieldtoFilter

$banner = Mage::getModel('mymodulename/banner')->getCollection();

Now I wish to show banner whose status are active. I already have a field name/column name 'status' in my custom table.

$banner -> addFieldToFilter('status', array('eq' => 1));

Now I will sort the result according to sort order in my table. I already have a field name 'sort_order' in my table. To sort according to that column I will write

$banner -> setOrder('sort_order', 'DESC');

1 comment:

  1. Great! how can we add custom filter to multiple fields.