我正在为 Magento 开发一个模块,它调用 Web 服务并添加 cookie。我希望在保存用户时调用类中的方法( customer_save_after )。在本地主机上开发时,我以某种方式能够让它工作,但我在尝试实现它的实时站点上收到此错误:
Mage registry key "_singleton/Eight18_Aqui4_Model_Observer" already exists
有一个类似的线程 here ,但它忽略了如何解决问题的实际细节。
这是我的 config.xml: (customer_save_after 事件似乎是错误开始的地方)
<?xml version="1.0"?>
<config>
<global>
<helpers>
<aqui4>
<class>Eight18_Aqui4_Helper</class>
</aqui4>
</helpers>
<modules>
<Eight18_aqui4>
<version>0.1.0</version>
</Eight18_aqui4>
</modules>
</global>
<adminhtml>
<acl>
<resources>
<all>
<title>Allow Everything</title>
</all>
<admin>
<children>
<Eight18_Aqui4>
<title>Aqui4 Module</title>
<sort_order>10</sort_order>
</Eight18_Aqui4>
</children>
</admin>
</resources>
</acl>
<layout>
<updates>
<aqui4>
<file>aqui4.xml</file>
</aqui4>
</updates>
</layout>
</adminhtml>
<default>
<main>
<enable>1</enable>
<siteid>0</siteid>
<sitetoken>0</sitetoken>
</main>
</default>
<frontend>
<events>
<customer_save_after>
<observers>
<aqui4_observer>
<class>Eight18_Aqui4_Model_Observer</class>
<method>start_aqui4</method>
</aqui4_observer>
</observers>
</customer_save_after>
</events>
<routers>
<aqui4>
<use>standard</use>
<args>
<module>Eight18_Aqui4</module>
<frontName>aqui4</frontName>
</args>
</aqui4>
</routers>
<layout>
<updates>
<aqui4>
<file>aqui4.xml</file>
</aqui4>
</updates>
</layout>
</frontend>
</config>
/Company/Module/Model/observer.php:
Public function start_aqui4() {//THIS IS CALLED BY THE EVENT OBSERVER ON CUSTOMER CREATION
// get variables
$userEmail = Mage::helper('aqui4')->getUserEmail();
$userFirstName = Mage::helper('aqui4')->getUserFirstName();
$userLastName = Mage::helper('aqui4')->getUserLastName();
$siteID = Mage::helper('aqui4')->getSiteID();
$siteToken = Mage::helper('aqui4')->getSiteToken();
$expire=time()+60*60*24*30.42*6;//THE LAST NUMBER IS THE MONTHS
$randomNumber = rand(0, pow(10, 5));//SERVICE EXPECTS RAND NUMBER
if(isset( $_COOKIE['aqui4userid'] )){//CHECK TO SEE IF USER ALREADY HAS A COOKIE
return;
}
else{//CHANGE JSON DATA SO JSON_DECODE CAN READ IT
$getContent = file_get_contents("http://www.domain.com/service.ashx?siteId=" . $siteID . "&token=" . $siteToken . "&email=" . $userEmail . "&data={\"firstName\":\"" . $userFirstName . "\",\"lastName\":\"" . $userLastName . "\",\"email\":\"" . $userEmail . "\",\"company\":\"\",\"position\":\"\",\"country\":\"\"}", true);
$getContent = str_replace('function __authenticate() ', '', $getContent);
$getContent = str_replace('{ return ', '', $getContent);
$getContent = str_replace(';}', '', $getContent);
$getContent = str_replace('\'', '"', $getContent);
$getContent = str_replace(': "', ':"', $getContent);
//SET THE USER ID AND ERROR VARS BASED ON DATA PASSED BACK
$getContentArray = json_decode($getContent, true);
$error = $getContentArray['HasError'];
$userID = $getContentArray['UserId'];
if($error){
if($error != "True"){//SERVICE RETURNS NO ERROR
setcookie("aqui4userid", $userID, $expire);
return;
}
else{//NO COOKIE SET - USER WAS NOT ADDED
return;
}
}
}
}
}
最后是 system.log 文件:
2012-07-24T23:21:52+00:00 ERR (3): Warning: include(/var/www/clients/client3/web4/web/includes/src/Eight18_Aqui4_Model_Observer.php): failed to open stream: No such file or directory in /var/www/clients/client3/web4/web/includes/src/Varien_Autoload.php on line 93
2012-07-24T23:21:52+00:00 ERR (3): Warning: include(): Failed opening '/var/www/clients/client3/web4/web/includes/src/Eight18_Aqui4_Model_Observer.php' for inclusion (include_path='/var/www/clients/client3/web4/web/includes/src:.:/usr/share/php:/usr/share/pear') in /var/www/clients/client3/web4/web/includes/src/Varien_Autoload.php on line 93
2012-07-24T23:21:52+00:00 ERR (3): Warning: include(/var/www/clients/client3/web4/web/includes/src/Eight18_Aqui4_Model_Observer.php): failed to open stream: No such file or directory in /var/www/clients/client3/web4/web/includes/src/Varien_Autoload.php on line 93
2012-07-24T23:21:52+00:00 ERR (3): Warning: include(): Failed opening '/var/www/clients/client3/web4/web/includes/src/Eight18_Aqui4_Model_Observer.php' for inclusion (include_path='/var/www/clients/client3/web4/web/includes/src:.:/usr/share/php:/usr/share/pear') in /var/www/clients/client3/web4/web/includes/src/Varien_Autoload.php on line 93
2012-07-24T23:21:54+00:00 ERR (3): Warning: include(/var/www/clients/client3/web4/web/includes/src/Eight18_Aqui4_Model_Observer.php): failed to open stream: No such file or directory in /var/www/clients/client3/web4/web/includes/src/Varien_Autoload.php on line 93
2012-07-24T23:21:54+00:00 ERR (3): Warning: include(): Failed opening '/var/www/clients/client3/web4/web/includes/src/Eight18_Aqui4_Model_Observer.php' for inclusion (include_path='/var/www/clients/client3/web4/web/includes/src:.:/usr/share/php:/usr/share/pear') in /var/www/clients/client3/web4/web/includes/src/Varien_Autoload.php on line 93
最佳答案
简短版本:您的生产系统正在“编译器模式”下运行,并且您尚未编译模块类。
您的生产服务器正在运行,且 Magento 的“compiler mode ”(自链接)已打开。您可以通过 Magento 的日志记录错误消息来判断
ERR (3): Warning: include(): Failed opening '/var/www/clients/client3/web4/web/includes/src/Eight18_Aqui4_Model_Observer.php'
for inclusion (include_path='/var/www/clients/client3/web4/web/includes/src:.:/usr/share/php:/usr/share/pear') in /var/www/clients/client3/web4/web/includes/src/Varien_Autoload.php on line 93
Magento 在 includes/src
中查找类。这就是编译类的放置位置。此外,PHP 尝试包含完全下划线的文件名 Eight18_Aqui4_Model_Observer.php
。仅当编译器模式打开时才会发生这种情况。
当您将模块更改推送到生产环境时,您需要重新编译模块。您可以从
执行此操作System -> Tools -> Compilation
或者使用命令行编译脚本
$ php shell/compiler.php
Usage: php -f compiler.php -- [options]
state Show Compilation State
compile Run Compilation Process
clear Disable Compiler include path and Remove compiled files
enable Enable Compiler include path
disable Disable Compiler include path
help This help
关于magento 注册表已经,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11640822/