如何通过在magento中查询来限制数据

问题描述:

我是magento的新手,我正在自定义对产品,类别和主页的一些更改。我已经writen下面的代码显示主页上的所有类别如何通过在magento中查询来限制数据

public function getRandomCategory() 
{ 
    $categoryCollection = Mage::getModel('catalog/category') 
    ->getCollection() 
    ->addAttributeToSelect('*'); 

    $categoryCollection->getSelect()->order('RAND()'); 

    return $categoryCollection; 
} 

我怎么会通过在*的情况下使用的条件限制数据 - > addAttributeToSelect(“*”);声明

+0

限制数据...这不是很清楚,但我会尽力涵盖所有我的答案 –

你可以做调试很酷的事情就是打电话

echo $categoryCollection->getSelect(); 

,它将返回Magento的确切查询generatingm现在addAttributeToSelect(“*”),它的作用是产生“选择* from ...'查询的一部分让我们假设您只需要检索类别名称

在这种情况下,您只需要执行 - > addAttributeToSelect('name')you_可以添加多个 - > addAttributeToSelect('属性')来检索多个值。

现在,如果通过限制你的意思是数据只有在一些= tosomething别人,那么你需要使用addAttributeToFilter检索类别(“atttribute”,“”)值

检查using_collections_in_magento有关

更多信息

希望我的回答有帮助