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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With