Autoloading a class in Symfony 2.1

前端 未结 2 980
囚心锁ツ
囚心锁ツ 2020-12-11 17:37

I\'m porting a Symfony 1.2 project to Symfony 2.x. I\'m currently running the latest 2.1.0-dev release.

From my old project I have a class called Tools which has som

2条回答
  •  渐次进展
    2020-12-11 18:28

    Another way is to use the /app/config/autoload.php:

    add( 'YOURNAMESPACE', __DIR__.'/../vendor/YOURVENDOR/src' );
    
    
    // intl
    if (!function_exists('intl_get_error_code')) {
        require_once  _DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';
    
        $loader->add('', __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs');
    }
    
    AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
    
    return $loader;
    

    Just replace YOURNAMESPACE and YOURVENDOR with your values. Works quite well for me, so far.

    You're correct, I stumbled upon the changes in autoload from 2.0 to 2.1. The above code works fine with the latest version, to which I upgraded my project ;-)

提交回复
热议问题