Pimcore自定义类
问题描述:
我写了自定义类,并希望在pimcore应用程序中使用它们。 我把它们带到服务器上的/website/lib/Custom目录。之后,我为位于目录中的每个Class编写了递归脚本包含器,并将该脚本包含在/index.php文件中。Pimcore自定义类
这绝对不是pimcore标准,但它的工作原理。
在pimcore /配置/ startup.php存在片断:
$autoloaderClassMapFiles = [
PIMCORE_CONFIGURATION_DIRECTORY . "/autoload-classmap.php",
PIMCORE_CUSTOM_CONFIGURATION_DIRECTORY . "/autoload-classmap.php",
PIMCORE_PATH . "/config/autoload-classmap.php",
];
$test = PIMCORE_ASSET_DIRECTORY;
foreach ($autoloaderClassMapFiles as $autoloaderClassMapFile) {
if (file_exists($autoloaderClassMapFile)) {
$classMapAutoLoader = new \Pimcore\Loader\ClassMapAutoloader([$autoloaderClassMapFile]);
$classMapAutoLoader->register();
break;
}
}
我想,这提供包含所有这些投入返回数组从自动加载,classmap.php类。 考虑到/pimcore/config/autoload-classmap.php存在,所提及的循环会在第一次迭代时中断,因此我将放入自定义autoload-classmap的类将不会包含在项目中。
我的问题是我可以更改/pimcore目录中的文件,并期望系统更新后的一切都会好吗?
答
不,您不应该覆盖pimcore目录中的任何内容,因为其中的文件会被更新机制覆盖。
你可以做你想做的使用将不会被覆盖的/website/config/startup.php: https://www.pimcore.org/wiki/display/PIMCORE4/Hook+into+the+startup-process
但不是加载所有的类都像你一样,利用自动加载器通过添加该到/website/config/startup.php:如果您正确使用名称空间
// The first line is not absolutely necessary, since the $autoloader variable already gets
// set in the /pimcore/config/startup.php, but it is a more future-proof option
$autoloader = \Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('Custom');
,并命名您的文件正确这就是你需要做的。