CaptainStiggz
CaptainStiggz

Reputation: 1897

Class not found Symfony2

I've installed the ffmpeg.so extension on my server. I want to use the ffmpeg-php library in my Symfony 2 application. If I do:

$ffmpeg = new ffmpeg_movie('movie.flv');

In a standalone php file, it works beautifully. But if I put the same code into my Symfony2 controller, I get

Fatal error: Class 'Example\ExampleBundle\Controller\ffmpeg_movie' not found in...

It must have to do with Symfony's namespace options, but I'm not sure how to resolve it.

Upvotes: 0

Views: 1051

Answers (2)

noetix
noetix

Reputation: 4923

When you're within a particular namespace, any class references without a namespace will be treated as a class local to that namespace. In your example, its treating ffmpeg_movie as a Example\ExampleBundle\Controller namespace class.

If you want to access another namespace, which includes the global namespace (which includes PHP classes, interfaces, as well as any custom defined global items), you have two choices.

  1. Access it using it's full namespace (which is \ for global) & class name:

    $obj = new \ffmpeg_movie;
    $obj = new \DateTime;
    
  2. Reference the external class using use:

    use ffmpeg_movie;
    use DateTime as AwesomeDateTimeClass;
    
    $obj = new ffmpeg_movie;
    $obj = new AwesomeDateTimeClass;
    

Upvotes: 1

CaptainStiggz
CaptainStiggz

Reputation: 1897

Oops, turns out you can just add

use ffmpeg_movie; 

At the top of your controller, same as any other class. Silly me.

Upvotes: 0

Related Questions