在自定义 Magento 模块中使用 PEAR 库会产生“需要打开失败...”错误

发布于 2024-11-16 07:01:11 字数 1261 浏览 0 评论 0 原文

我编写了一个 Magento 模块来监听“OrderSave”事件并对第三方应用程序执行一些 API 调用。大多数功能都运行良好,但我需要处理来自 API 的 XML 响应,当我尝试使用 PEAR XML_Unserializer 类时,我收到以下错误:

致命错误:require_once() [function.require]:无法打开所需的“XML/Parser.php” (include_path='/Users/jeremymoore/Sites/Helm/html/app/code/local:/Users/jeremymoore/Sites/Helm/html/app/code/community:/Users/jeremymoore/Sites/H elm/html/app/code/core:/Users/jeremymoore/Sites/Helm/html/lib:.:/Applications/MAMP/bin/php5/lib/php:/usr/loca/zend//share/ZendFramework/图书馆')在 /Users/jeremymoore/Sites/Helm/html/lib/PEAR/XML/Unserializer.php 第 58 行

我的模块在模型中有一个 Observer.php 文件,其开头如下:

<?php
require_once 'lib/PEAR/XML/Serializer.php';
require_once 'lib/PEAR/XML/Unserializer.php';
require_once 'lib/Pest/PestXML.php';
Zend_Loader::registerAutoload();

class Helm_Litmos_Model_Observer
{
    public function hookToOrderSaveEvent()
    {
        //Do API Stuff Here
    }
}

hookToOrderSaveEvent 函数创建序列化器的新实例和反序列化器类。在添加反序列化器代码之前,我已经完成了序列化对象和进行 API 调用的所有工作。当 XML_Unserializer 类尝试引用 Parser.php 时,事情似乎崩溃了。

我不确定我在这里使用的“require_once”方法是否适合我包含这些库。我正在使用 Magento 1.4.1.1,目前正在运行 MAMP 的本地计算机上使用。

任何关于自动加载或包含这些库以在我的模块中使用的更好方法的建议,或者只是关于如何修复我所拥有的内容的想法,将不胜感激。

谢谢

I have written a Magento module to listen for the "OrderSave" event and perform some API calls to a third party application. Most of the functionality is working great, but I needed to handle an XML response from the API and when I tried to use the PEAR XML_Unserializer class I received the following error:

Fatal error: require_once() [function.require]: Failed opening required 'XML/Parser.php' (include_path='/Users/jeremymoore/Sites/Helm/html/app/code/local:/Users/jeremymoore/Sites/Helm/html/app/code/community:/Users/jeremymoore/Sites/Helm/html/app/code/core:/Users/jeremymoore/Sites/Helm/html/lib:.:/Applications/MAMP/bin/php5/lib/php:/usr/loca/zend//share/ZendFramework/library') in /Users/jeremymoore/Sites/Helm/html/lib/PEAR/XML/Unserializer.php on line 58

My module has an Observer.php file in the model which looks starts as follows:

<?php
require_once 'lib/PEAR/XML/Serializer.php';
require_once 'lib/PEAR/XML/Unserializer.php';
require_once 'lib/Pest/PestXML.php';
Zend_Loader::registerAutoload();

class Helm_Litmos_Model_Observer
{
    public function hookToOrderSaveEvent()
    {
        //Do API Stuff Here
    }
}

The hookToOrderSaveEvent functon creates new instances of the serializer and unserializer classes. Before I added the Unserializer code, I had everything working serializing objects and making API calls. It seems that things break down when the XML_Unserializer class tries to reference Parser.php.

I'm not sure that the "require_once" method I'm using here is the appropriate way for me to include these libraries. I'm using Magento 1.4.1.1 which is currently being used on my local machine running MAMP.

Any suggestions on a better way to autoload or include these libraries for use in my module or just ideas on how to fix what I have would be appreciated.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

誰ツ都不明白 2024-11-23 07:01:11

您可以尝试使用 Mage::getBaseDir('lib')

require_once Mage::getBaseDir('lib').'/PEAR/XML/Serializer.php';

Alan 有一篇关于 Magento 基本目录的好文章:

http://alanstorm.com/magento_base_directories

You can try and use Mage::getBaseDir('lib')

require_once Mage::getBaseDir('lib').'/PEAR/XML/Serializer.php';

Alan has a good article on Magento's base directories:

http://alanstorm.com/magento_base_directories

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文