Question

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?

Was it helpful?

Solution 2

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.

OTHER TIPS

Into vendor/composer/autoload_classmap.php (Symfony 2.1)

<?php

// autoload_classmap.php generated by Composer

$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);

return array(
    'EasyCSV' => __DIR__.'/../vendor/easy-csv',
    [....]
);

and then you can use it simply by insert

use EasyCSV

"at the top" of the file where you need it.

Without composer solution

Try this into your autoload.php file (at the bottom, I suppose)

use Symfony\Component\ClassLoader\MapClassLoader;
[...]
// Create map autoloader
$mapLoader = new MapClassLoader(array(
    'EasyCSV' => __DIR__.'/../vendor/easy-csv',
    [...]
));

// Register autoloader
$mapLoader->register();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top