您可以在Symfony 1.4框架中使用Symfony2中的Autoloader.
原文链接:https://www.f2er.com/php/135682.html1.将Symfony2类加载器复制到Symfony 1.4沙箱项目的供应商目录:
SF_ROOT_DIR/lib/vendor/Symfony2/src/Symfony/Component/ClassLoader/UniversalClassLoader.PHP
SF_ROOT_DIR/lib/vendor/Symfony2/src/Symfony/Component/ClassLoader/ApcUniversalClassLoader.PHP
2.修改SF_ROOT_DIR / config / ProjectConfiguration.class.PHP文件,如下所示:
require_once dirname(__FILE__) . '/../lib/vendor/symfony/lib/autoload/sfCoreAutoload.class.PHP'; require_once dirname(__FILE__) . '/../lib/autoload/sfClassLoader.class.PHP'; sfCoreAutoload::register(); class ProjectConfiguration extends sfProjectConfiguration { public function setup() { $this->namespacesClassLoader(); $this->enablePlugins('sfDoctrinePlugin'); } public function namespacesClassLoader() { if (extension_loaded('apc')) { $loader = new ApcUniversalClassLoader('S2A'); } else { $loader = new UniversalClassLoader(); } $loader->registerNamespaces(array( 'Pohon' => __DIR__ . '/../lib/vendor/Pohon/src')); $loader->register(); } }
3.注册所需的命名空间:
例如.我想加载类:
Pohon\Tools\String\Utils\Slugify.
文件名必须是:
SF_ROOT_DIR/lib/vendor/Pohon/src/Pohon/Tools/String/Utils/Slugify.PHP
和注册的命名空间如下:
Pohon => SF_ROOT_DIR/lib/vendor/Pohon/src