Magento Observer 函数与外部 PHP 类错误
我正在尝试完成一些我认为超出我当前 PHP 技能的事情! 我在 Magento .phtml 模板文件中有工作代码,它调用外部 PHP 类,例如
$ExternalLibPath=Mage::getModuleDir('', 'My_Module') . DS . 'lib' . DS .'class.authentication.php';
require_once ($ExternalLibPath);
$myauth = new Authentication();
$credentials = $myauth->get("account_credentials");
echo "Connecting as " . $credentials->user_name ;
(在 .phtml 文件中,从包含中调用类)。我正在尝试将代码从前端模板文件移动到具有事件触发类的 Magento 模块/扩展。我的模块工作正常,直到访问外部类,其中尝试访问 *$credentials->user_name* 会导致未定义的属性:stdClass:错误。
我不明白为什么代码在 .phtml 模板中工作而不是在模块中工作,或者我做错了什么!
任何帮助将不胜感激。
皮特.
I am trying to accomplish something which I think is getting beyond my current PHP skills!
I have working code in a Magento .phtml template file that calls an external PHP class e.g.
$ExternalLibPath=Mage::getModuleDir('', 'My_Module') . DS . 'lib' . DS .'class.authentication.php';
require_once ($ExternalLibPath);
$myauth = new Authentication();
$credentials = $myauth->get("account_credentials");
echo "Connecting as " . $credentials->user_name ;
(In the .phtml file the classes are called from an include). I'm trying to move the code from the frontend template files to a Magento module/extension with a class triggered on an event. My module works fine up until the external classes are accessed where trying to access *$credentials->user_name* causes an Undefined property: stdClass: error.
I don't understand why the code works in a .phtml template and not in the module, or what I am doing wrong!
Any help would be appreciated.
Pete.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该直接从 phtml 调用该类:
$credentials = Mage::getModel('namespace/custom_class')->getAccountCredentials();
并返回您需要的任何内容。
You should call the class directly from the phtml:
$credentials = Mage::getModel('namespace/custom_class')->getAccountCredentials();
and return whatever you need to.