Php !类不在magento中工作?
当我运行test.php时,为什么总是出错!类_行 这是test.php:Php !类不在magento中工作?,php,magento,Php,Magento,当我运行test.php时,为什么总是出错!类_行 这是test.php: <?php //test.php require_once './app/Mage.php'; Mage::app()->setCurrentStore(0); Mage::setIsDeveloperMode(true); require_once("test-class.php"); ?> 这是test-class.php: <?php /
<?php //test.php
require_once './app/Mage.php';
Mage::app()->setCurrentStore(0);
Mage::setIsDeveloperMode(true);
require_once("test-class.php");
?>
这是test-class.php:
<?php //test-class.php
if (!class_exists("AClass")) {
class AClass {
public function AnAction() {
return 123;
}
}
}
?>
因为Magento引导应用程序/Mage.php,所以对
class\u exists()的调用会触发尝试加载该类的类定义。通过传递false
,可以更改此行为:
<?php //test-class.php
if (!class_exists("AClass",false)) {
class AClass {
public function AnAction() {
return 123;
}
}
}
?>
将您的类定义放在上述任何目录中都将允许在需要定义时对其进行定义
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'local';
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'community';
$paths[] = BP . DS . 'app' . DS . 'code' . DS . 'core';
$paths[] = BP . DS . 'lib';