Adam Stacey
Adam Stacey

Reputation: 2831

How to do you include a class in Symfony2?

I have read the Symfony documentation and I am still unsure of how to include a class. I want to include a Google Analytics PHP class into Symfony, but not sure on the following:

  1. Where should it go? From the documentation I assume it should be under the vendor directory?
  2. How would I then include the class? Ideally I would only like to include it where necessary (ie when I need it).
  3. How would I then utilise the class?

Cheers

Adam

Upvotes: 4

Views: 1095

Answers (1)

catalin.costache
catalin.costache

Reputation: 3163

Use the app/autoload.php file to configure your autoload mechanism.

If your class doesn't follow PEAR style conventions or PSR-0 standards then you should plainly require it (as is the case with Swiftmailer in the same file)

If your class follows PEAR conventions then you should use registerPrefixes method else, if your class follows PSR-0 standard (maybe not the case), you should use the registerNamespaces method

Upvotes: 6

Related Questions