【发布时间】:2011-08-08 19:26:49
【问题描述】:
我有一个文件 (js.phtml) 用于执行我的代码。我需要访问一些用户数据。当我在 js.phtml 中出现 error_log($this) 时,它会显示“Mage_Core_Block_Template”——这让我很困惑。我希望它是父类,而不是传递给我的 .phtml 文件的类的值。
那么,如何为 .phtml 文件提供自定义对象或方法?我是 Magento 的超级新手,我刚刚被投入一项任务,所以我为可能使用不正确的术语道歉。
编辑: 我的完整文件路径是:
- /app/design/frontend//default/template/customer/welcome/js.phtml
这里还有一个完整的模块目录:
- /app/code/local//客户/
编辑: 我需要访问用户的国家和用户 ID。 country 为 null 也没关系。
编辑: 我一直在做额外的研究,看起来我可以做这样的事情: Current user in Magento?
但我还没有在代码中尝试过......
编辑:想通了:
error_log(print_r(Mage::getSingleton('customer/session')->getCustomer()->getEntityId(), true));
error_log(print_r(Mage::getSingleton('customer/session')->getCustomer()->getCountry(), true));
【问题讨论】:
-
您需要使用哪些对象/方法?您能否再描述一下您的 js.phtml 文件要完成的工作?
-
您的路径有问题。默认主题模板文件夹的路径是
\app\design\frontend\base\default\template。