我是magento的新手,我正在定制产品,类别和主页的一些更改。我已经编写了以下代码来显示主页上的所有类别
public function getRandomCategory()
{
$categoryCollection = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('*');
$categoryCollection->getSelect()->order('RAND()');
return $categoryCollection;
}
如何限制数据使用条件的情况下* in ->addAttributeToSelect('*');声明
调试时可以做的一件很酷的事情是调用
echo $categoryCollection->getSelect();
,它将返回magento正在生成的确切查询,现在addAttributeToSelect('*')它所做的是生成'Select * From…的一部分,假设您只需要检索类别名称
在这种情况下,你只需要做->addAttributeToSelect('name'),你_可以添加多个->addAttributeToSelect('attribute')来检索多个值。
现在,如果通过限制数据,你意味着只检索类别WHERE something =别的东西,那么你需要使用addAttributeToFilter(' attribute ', ")值
查看using_collections_in_magento获取更多关于
的信息希望我的回答有帮助