Good practice in handling includes & requires

What are good practices in handling includes and requires of huge/small third party libraries?

I already made use of autloading, but there are scenarios where autoloading does not help.

If you download huge external libraries like SwiftMailer or Google API, the filename is not really similar to their classnames and contains lots of files which actually use the native "include" and "require" functions.

Sometimes we just want to separate a part of our code from the body of a function to a sperate file.

If i need to include bunch of php files to my components or a portion of the body of a function I do this:


        public function showErrorPage()


            $applicationPath = Yii::getPathOfAlias('webroot');  



If I need to include the google API library which has lots of baggage on it I could do it this way

        $applicationPath = Yii::getPathOfAlias('webroot'); 

        // Google Adwords API Library


Is there a specific Yii-way to do this?

There’s not really a Yii-specific way AFAIK, but this is a neat way of doing it:


If you put your vendor code in a ‘vendor’ directory in a subdirectory of your component/widget/whatever.

And another - probably more Yii-ish (which I use for my Rss feed code), using the application-wide ‘vendors’ directory:




HTH :)

Almost every library provides its own autoloader (as SwiftMailer does, for example). Just register it with Yii::registerAutoloader().