0

使用 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;
4

2 回答 2

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();
于 2013-05-17T05:03:52.950 回答
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();
于 2013-05-18T06:47:35.533 回答