2013-10-24 77 views
0

我想在特定類別下顯示一些文本。爲此,我想獲得類別ID。我在top.phtml(自定義設計)中打印類別數組,如下所示;如何解析magento對象

<?php foreach ($this->getStoreCategories() as $_category): ?> 

print_r($_category); 

以上的print_r給出的結果below.How我可以分析以下對象來獲取ENTITY_ID(這裏它的值是1013)或名稱(這裏是「殊榮長相」)。

Mage_Catalog_Model_Category Object 
(
[_eventPrefix:protected] => catalog_category 
[_eventObject:protected] => category 
[_cacheTag:protected] => catalog_category 
[_useFlatResource:protected] => 1 
[_designAttributes:Mage_Catalog_Model_Category:private] => Array 
    (
     [0] => custom_design 
     [1] => custom_design_from 
     [2] => custom_design_to 
     [3] => page_layout 
     [4] => custom_layout_update 
     [5] => custom_apply_to_products 
    ) 

[_treeModel:protected] => 
[_defaultValues:protected] => Array 
    (
    ) 

[_storeValuesFlags:protected] => Array 
    (
    ) 

[_lockedAttributes:protected] => Array 
    (
    ) 

[_isDeleteable:protected] => 1 
[_isReadonly:protected] => 
[_resourceName:protected] => catalog/category_flat 
[_resource:protected] => 
[_resourceCollectionName:protected] => catalog/category_flat_collection 
[_dataSaveAllowed:protected] => 1 
[_isObjectNew:protected] => 
[_data:protected] => Array 
    (
     [entity_id] => 1013 
     [name] => Winning Looks 
     [path] => 1/2/1013 
     [is_active] => 1 
     [is_anchor] => 1 
     [request_path] => winning-looks.html 
     [id] => 1013 
    ) 

[_hasDataChanges:protected] => 1 
[_origData:protected] => 
[_idFieldName:protected] => entity_id 
[_isDeleted:protected] => 
[_oldFieldsMap:protected] => Array 
    (
    ) 

[_syncFieldsMap:protected] => Array 
    (
    ) 

) 

回答

1

你可以用<?php echo $category->getEntityId()?>

<?php foreach ($this->getStoreCategories() as $_category): 

    print_r($_category); 
    echo $_category->getEntityId() 

    endforeach; 
?> 

希望這會爲你工作得到。

+0

謝謝大家。它的工作:) – Abhilash

0

試試這個:

if ($_category->getId() == 1013){ //or $_category->getEntityId(); 
    //your magic code here 
} 
+0

//或$ _category-> getEntitId();應該是//或$ _category-> getEntityId();請不要介意 – liyakat

+0

@liyakat。你是對的。我不介意。我修復了它 – Marius