Search code examples
phpsymfonysymfony2

External Class is not autoloaded in symfony2.0 project


I want to add EasyCSV to my symfony2 project https://github.com/jwage/EasyCSV

This is what I tried. I added

'EasyCSV'          => __DIR__.'/../vendor/easy-csv',

to autoload.php and

use EasyCSV\Reader;

in my controller where I want to use this lib. But I get

Fatal error: Class 'EasyCSV\Reader' not found in ...Controller.php

Any ideas why? How to fix this?


Solution

  • As we discussed in the comments, make sure that you don't manually add third party libraries to your vendors file. The built-in symfony package management system is there for a reason.

    For the bundle in question, you should add the following to your deps file.

    [easy-csv]
        git=http://github.com/jwage/EasyCSV.git
    

    Then, you should add the following to your app/autoload.php

    $loader->registerNamespaces(array(
        ...
        'EasyCSV'          => __DIR__.'/../vendor/easy-csv/lib',
    ));
    

    Now you should be able to import the namespace and use it.