2014-03-07 51 views
1

在我更新XML我:Magento的產品佈局更新XML的SetData不工作

<reference name="content"> 
<remove name="product.info" /> 
<block type="catalog/product_view" template="catalog/product/imageview.phtml"> 
<action method="setData"><name>variable</name><value>3</value></action> 
</block> 
</reference> 

我已經創建imageview.phtml並加載正確。在這個模板我甩了以下內容:

var_dump($this->getVariable()); 

我預期的結果是:3

但結果是:NULL

我缺少什麼?

+0

是關鍵名稱'變量'或別的什麼?也許你調用的方法存在並返回'null'? – Marius

回答

0

嘗試給鑰匙一個不同的名字?

<action method="setData"> 
    <name>my_variable</name> 
    <value>3</value> 
</action> 

,並調用它像這樣

echo $this->getMyVariable(); 
3

老問題,但我知道我今天早上在同樣的問題來了。希望它能在一些時候拯救別人。

您的塊需要一個名稱才能通過setData方法接受任何變量。

<block type="catalog/product_view" name="product_image_view" template="catalog/product/imageview.phtml"> 
    <action method="setData"><name>variable</name><value>3</value></action> 
</block> 

不知道爲什麼它需要一個名字,因爲它似乎並沒有被記錄任何地方。可能值得加一個alais="product_image_view"以避免任何進一步Magentoism

+0

如果您想要傳遞產品方法的結果,該怎麼辦? – surfer190

+0

非常好,爲我工作 – arithran