9

I played with the zf2-tutorial successfully, but I was totally confused when trying to integrate an external library like "jpgraph". I know I must do this with autoload or servicemanager but it won't work. The php-files of jpgraph are in the vendor/graph directory. I use a module called Jpgraph, in the controller indexAction I try:

$graph = new Graph($width,$height);

this gives me an error:

Fatal error: Class 'Jpgraph\Controller\Graph' not found in ...

the jpgraph library don't use namespaces.

i also tried this way without success

what's the best way to integrate such things?

I would be glad for every tip or help

3
  • You're out of luck: JPGraph does not follow a PSR-0 structure, so the simple autoloader won't be able to do the work for you... Commented Oct 16, 2012 at 15:20
  • @Matteo not 100% true. While JPGraph does not follow a PSR-0 structure, there is still the option to use the ClassMapAutoloader, so he's not out of luck.
    – Luke Mills
    Commented Oct 16, 2012 at 22:03
  • @LukeMills I didn't thought about that! You're perfectly right, thanks for the correction. Commented Oct 17, 2012 at 7:13

2 Answers 2

2

Add the library to your composer.json and add the class with Classmap and/or the include path as phpunit does

https://github.com/sebastianbergmann/phpunit/blob/master/composer.json#L48

0
0

One option, as Maks3w pointed out, is to use Composer. If you've never heard of or used composer before it's definitely worth a look. I was surprised how easy it was to set up and use 3rd party libraries. It's also very easy to set up your own library to work with composer, and use any source controlled (git or svn) library of your own - works well with GitHub repos - just add a composer.json file.

On the other hand, you do not need to use composer to do what you want, it would make it very easy, but it may be overkill. Zend Framework 2 has a very flexible autoloader system, and although it works well with PSR-0, you can have any class autoloading sytem that you like. Take a look at the different components of Zend\Loader, in particular I think the ClassMapAutoloader will be the one to suit your needs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.