[英]Retrieve data from object - Magento
我試圖獲取所有類別id和他們的名字在magento。 為此,在我們的模板文件中,我添加了以下代碼:
$category = Mage::getModel('catalog/category')->getCollection()->getEntity();
echo '<pre>';
print_r($category);
echo '</pre>';
它返回以下對象。
Mage_Catalog_Model_Resource_Category Object
(
[_tree:protected] =>
[_categoryProductTable:protected] => catalog_category_product
[_isActiveAttributeId:protected] =>
[_storeId:protected] =>
[_attributes:protected] => Array
(
[42] => Array
(
[value_id] => 3
[entity_type_id] => 3
[attribute_id] => 42
[store_id] => 0
[entity_id] => 2
[value] => 1
)
[67] => Array
(
[value_id] => 4
[entity_type_id] => 3
[attribute_id] => 67
[store_id] => 0
[entity_id] => 2
[value] => 1
)
.................. going on ....
從這個對象得到attribute_id? 如果可以請我解釋..如果可以的話,還可以解釋收藏中有什么東西。 提前致謝。
嘗試這個:
$category = Mage::getModel('catalog/category')->getCollection();
foreach ($category as $cat)
{
$catObj = Mage::getModel('catalog/category')->load($cat->getEntityId());
//category Id
var_dump($catObj->getEntityId());
//category Name
var_dump($catObj->getName());
}
請記住,這會加載所有類別(在任何級別的后端創建的所有類別以及活動/非活動)。
您需要根據需要進行過濾。 為此,您可以過濾
$category = Mage::getModel('catalog/category')
->getCollection()
//ADD YOUR FILTERS HERE
/*LIKE THESE
->addIsActiveFilter()
->addLevelFilter(1) */
;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.