表达式引擎->可以在一个模板中包含 Magento 代码,但不能在另一个模板中包含 Magento 代码
我们的网站将 Magento 与 EE 结合使用。在我的一个模板中,我有以下代码来加载要在模板中使用的 Magento 对象模型:
include_once($_SERVER['DOCUMENT_ROOT'] . '/store/app/Mage.php');
Mage::app();
模板加载正常并且代码有效。
但是,如果我在另一个模板中包含完全相同的代码,我会得到:
Fatal error: Uncaught exception 'Exception' with message 'Warning: include(Query.php):
failed to open stream:
No such file or directory in /srv/www/htdocs/store/lib/Varien/Autoload.php on line 93' in /srv/www/htdocs/store/app/code/core/Mage/Core/functions.php:245
Stack trace:
#0 /srv/www/htdocs/store/lib/Varien/Autoload.php(93): mageCoreErrorHandler(2, 'include(Query.p...', '/srv/www/htdocs...', 93, Array)
#1 /srv/www/htdocs/store/lib/Varien/Autoload.php(93): Varien_Autoload::autoload()
#2 [internal function]: Varien_Autoload->autoload('query')
#3 [internal function]: spl_autoload_call('query')
#4 /srv/www/htdocs/na_cms/expressionengine/libraries/Template.php(1089): class_exists('query')
#5 /srv/www/htdocs/na_cms/expressionengine/libraries/Template.php(968): EE_Template->process_tags()
#6 /srv/www/htdocs/na_cms/expressionengine/libraries/Template.php(497): EE_Template->tags()
#7 /srv/www/htdocs/na_cms/expressionengine/libraries/Template.php(248): EE_Template->parse('??
这些模板不是嵌套的。
有什么想法为什么会发生这种情况以及如何解决它吗?
We use Magento in conjunction with EE for our site. In one of my templates, I have this code to load the Magento object model to be used in the template:
include_once($_SERVER['DOCUMENT_ROOT'] . '/store/app/Mage.php');
Mage::app();
The template loads fine and the code works.
But if I include the exact same code in another template, I get this:
Fatal error: Uncaught exception 'Exception' with message 'Warning: include(Query.php):
failed to open stream:
No such file or directory in /srv/www/htdocs/store/lib/Varien/Autoload.php on line 93' in /srv/www/htdocs/store/app/code/core/Mage/Core/functions.php:245
Stack trace:
#0 /srv/www/htdocs/store/lib/Varien/Autoload.php(93): mageCoreErrorHandler(2, 'include(Query.p...', '/srv/www/htdocs...', 93, Array)
#1 /srv/www/htdocs/store/lib/Varien/Autoload.php(93): Varien_Autoload::autoload()
#2 [internal function]: Varien_Autoload->autoload('query')
#3 [internal function]: spl_autoload_call('query')
#4 /srv/www/htdocs/na_cms/expressionengine/libraries/Template.php(1089): class_exists('query')
#5 /srv/www/htdocs/na_cms/expressionengine/libraries/Template.php(968): EE_Template->process_tags()
#6 /srv/www/htdocs/na_cms/expressionengine/libraries/Template.php(497): EE_Template->tags()
#7 /srv/www/htdocs/na_cms/expressionengine/libraries/Template.php(248): EE_Template->parse('??
These templates are NOT nested.
Any ideas why this is happening and how to fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的代码或 EE 代码中的某个时刻,您尝试使用名为“Query”的类。该类未定义,因此 PHP 尝试使用其自动加载器机制来加载 Query 类。
上面的代码表明 Magento 的自动加载尝试加载类 Query。这会失败(因为该类不是 Magento 类)。此外,您似乎处于 Magento 的开发人员模式中,所有通知和警告都变成了异常。由于自动加载失败并出现警告,因此会引发致命异常。
所以,问题可能是两件事。第一个是有人试图实例化一个不存在的 Query 类。如果是这种情况,请停止这样做。
第二个是 Query 类存在,但 EE 的自动加载器永远没有机会加载它,因为 Magento 的自动加载会先尝试。如果是这种情况,您需要在某处插入一些代码来调整自动加载器以更改其顺序。您还可以尝试手动包含 Query 类来修复此特定实例。
At some point in your code, or the EE code, you're trying to use a class named "Query". This class is undefined, so PHP attempts to use its autoloader mechanism to load the class Query.
The code above indicates Magento's autoload tries to load the class Query. This fails (as the class isn't a Magento class). Also, it appears you're in Magento's developer mode, where all Notices and warnings are turned into Exceptions. Since the autoload fails with a warning, a fatal exception is thrown.
So, the problem could be two things. The first is someone's trying to instantiate a non-existant Query class. If this is the case, stop doing it.
The second is that the Query class exists, but EE's autoloader never has a chance to load it because Magento's autoload tries first. If this is the case you'll need to insert some code somewhere that jiggers the autoloaders to change their order. You could also try manually including the Query class to fix this specific instance.