简体   繁体   English

你如何在Symfony2中包含一个类?

[英]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. 我已经阅读了Symfony文档,我仍然不确定如何包含一个类。 I want to include a Google Analytics PHP class into Symfony, but not sure on the following: 我想将一个Google Analytics PHP类包含在Symfony中,但不确定如下:

  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 亚当

Use the app/autoload.php file to configure your autoload mechanism. 使用app/autoload.php文件配置自动加载机制。

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) 如果您的类不遵循PEAR样式约定或PSR-0标准,那么您应该明确地要求它(与同一文件中的Swiftmailer一样)

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 如果你的类遵循PEAR约定,那么你应该使用registerPrefixes方法,如果你的类遵循PSR-0标准(可能不是这种情况),你应该使用registerNamespaces方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM