Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use composer with my Yii application

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.

like image 281
user3651456 Avatar asked May 19 '14 06:05

user3651456


People also ask

What is Composer in Yii2?

Composer is a tool for dependency management in PHP. Yii2 uses it to install itself and other vendors' modules (for example, bootstrap). It is also possible to install Yii2 in the old way, by downloading the complete package and transferring it to the host, local or remote, where the framework will be installed.

Is Yii hard to learn?

Yii has a low-entry barrier. In other words, it is really easy to learn. Developers describe it as a PHP framework that is most simple.

What is difference between Yii and Yii2?

Conceptually Yii1 and Yii2 are quite similar, however Yii2 runs on newer PHP versions and utilizes namespaces, traits etc. Yii2 has also support for dependency injection through $container singleton available after initializing the framework.


1 Answers

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.

like image 77
Blizz Avatar answered Sep 28 '22 02:09

Blizz