我编写了一个 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
发布评论
评论(1)
您可以尝试使用
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