将帮助器中的公共变量导入模板

时间:2013-05-16 18:28:03

标签: php magento

使用Magento我在类中定义了一个变量:

在app / code / local / Me / MyMod / Helper / 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;

2 个答案:

答案 0 :(得分: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();

答案 1 :(得分: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();