Search code examples
symfonycomposer-phpautoloader

Symfony2 - Composer class loader instance in controller


Is there a way to get the composer autoloader instance inside a Symfony2 Controller?


Solution

  • Yes - there is a way.

    And assuming that you want to know how to actually get the loader then you can do this in your controller:

    class MyController
        function myAction()
        {
            die(get_class($GLOBALS['loader'])); // Composer\Autoload\ClassLoader
    

    Should you do this? Probably not. In most cases you can tweak the loader in the app/autoload.php file.