Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有外部PHP类的Magento Observer函数错误_Php_Class_Magento_Module - Fatal编程技术网

带有外部PHP类的Magento Observer函数错误

带有外部PHP类的Magento Observer函数错误,php,class,magento,module,Php,Class,Magento,Module,我正在努力完成一些我认为超出我目前PHP技能的事情! 我在Magento.phtml模板文件中使用了代码,该文件调用外部PHP类,例如 $ExternalLibPath=Mage::getModuleDir('', 'My_Module') . DS . 'lib' . DS .'class.authentication.php'; require_once ($ExternalLibPath); $myauth = new Authentication(); $credentials = $m

我正在努力完成一些我认为超出我目前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文件中,从include调用这些类)。我正在尝试将代码从前端模板文件移动到一个Magento模块/扩展,该模块/扩展带有一个事件触发的类。在访问外部类之前,我的模块工作正常,尝试访问*$credentials->user_name*会导致未定义的属性:stdClass:error

我不明白为什么代码在.phtml模板中工作而不在模块中工作,或者我做错了什么

任何帮助都将不胜感激


Pete.

您应该直接从phtml调用该类:

$credentials=Mage::getModel('namespace/custom_class')->getAccountCredentials()


然后返回您需要的任何内容。

定义“不工作”的含义(预期行为与实际行为)定义“模块中”的含义,您对该短语的使用与Magento社区对该术语的共同理解不符。预期行为-代码执行时不会出错,就像使用mysite/authenticate.phtml访问时一样,实际行为PHP异常错误!“在模块中”我指的是magento扩展,在app/code/local/MY/module/Model/code.php中使用app/code/local/MY/module/lib@Alan storm中的php类创建的代码,您看到的错误消息是什么?
Mage::getModule
不存在。sry-getModel,而不是getModule$myauth是从类创建的对象,带有“get”该类中返回帐户凭据的函数。确定。。。。get函数的作用是什么?你能在没有错误的情况下调用类中的其他函数吗?