我想在集合中创建一个IF条件。如果$mtype不为空,则此条件为addFieldToFilter('main_table.m_type', $mtype),如果条件不匹配,则此过滤器将不起作用。
$collection = Mage::getModel('manufacturers/manufacturers')->getCollection()
->addStoreFilter(Mage::app()->getStore(true)->getId())
->addFieldToFilter('main_table.status', 1)
->addFieldToFilter('main_table.m_type', $mtype)
->addOrder(Mage::helper('manufacturers')->getManufacturerSort(), Mage::helper('manufacturers')->getManufacturerOrder())
->getData();我希望你们知道这个问题的答案,或者你们能指导我做一个更好的方法。
谢谢,哈南·阿里
发布于 2012-01-06 22:10:46
$collection = Mage::getModel('manufacturers/manufacturers')->getCollection()
->addStoreFilter(Mage::app()->getStore(true)->getId())
->addFieldToFilter('main_table.status', 1)
->addOrder(Mage::helper('manufacturers')->getManufacturerSort(), Mage::helper('manufacturers')->getManufacturerOrder());
if (!empty($mtype)) {
$collection->addFieldToFilter('main_table.m_type', $mtype);
}
$data = $collection->getData();https://stackoverflow.com/questions/8758910
复制相似问题