How to use composer with my Yii application

composer-php, php, yii

Solution

I am assuming that you know how to create your composer.json and so on?

If so then you use `Composer` with Yii as you would with any other application.

You just have to modify Yii's classMap to make sure it picks up the loaded composer requirements. Edit your index.php (and probably also your `yiic.php` in the protected folder if you have one) and load the Composer autoloader and pass the map onto Yii:

$loader = require(__DIR__ . '/../vendor/autoload.php');
Yii::$classMap = $loader->getClassMap();

It is possible you have to modify the include path of course (my example assumes you have a `public_html`-folder.

If you also want to add your application classes to the map, so that you don't have to add aliases all the time:

"autoload": {
    "classmap": [
        "protected/"
    ],

Don't forget to run `composer dump-autoload` after you add classes then or it won't find them.

Problem

I have developed web app using Yii 1.1.3, and I am very much new with Core php, can anyone give me some detail that how I can use composer with Yii app. I have used Bootstrap, RESTFull Yii, yii-user and some other extensions. Your help will be appreciated.

Original source