2013-05-16 32 views
0

使用Magento的我有一类类似定义的变量:获取一个公共变量了帮手为模板

在app /代码

/本地/ ME/MyMod /助手/ Data.php

class Me_MyMod_Helper_Data extends Mage_Core_Helper_Abstract 
{ 
    public $theVar = 'I want this'; 
} 

然后在app/design/frontend/Me/some.phtml中查看如何获取这个变量?

Mage::helper('MyMod')->iDontKnowWhatIamDoing; 
+0

'$ x = new Me_MyMod_Helper_data(); echo $ x-> theVar' –

回答

1

你可以这样做:

class Me_MyMod_Helper_Data extends Mage_Core_Helper_Abstract 
{ 
    public $theVar = 'I want this'; 

    public function send_to_template() { 
     return $this->theVar; 
    } 
} 

而且在模板:

Mage::helper('MyMod')->send_to_template(); 
+0

正是我需要的,谢谢! – Zac

0

下面写功能Data.php

class Me_MyMod_Helper_Data extends Mage_Core_Helper_Abstract 
{ 
    public function getThis() 
    { 
    $theVar = 'I want this'; 
    return $theVar; 
    } 
} 

使用下面的代码

打电话给你的变量
echo Mage::helper('MyMod')->getThis();