The following columncomposerUsage Tutorialwill introduce you to the use of Composer in Yii2. I hope it will be helpful to friends in need!
#How to understand Composer?
If we use Composer, we should first know what it is and what it is mainly used for. We can understand Composer as a PHP package management tool to manage the Yii2 related plug-ins we use.
InstallationComposer
1. Installation under liunx
Download the composer.phar executable file and use the command php composer. phar can be executed.
2. Windows installation
Download Composer-Setup.exe and double-click to install it. For specific instructions, please refer to the steps for installing yii2 under win7 system
Execution of using composer under Linux Command: php composer.phar require --prefer-dist yiisoft/yii2-redis The red part is the directory and name of the plug-in.
Use composer execution command under windows: composer global require "fxp/composer-asset-plugin:1.2.0" The part marked in red is the plug-in name.
Composer in Yii2
When we open the directory after installing Yii2, we will see the composer.json file in the installation directory, which contains the required information and Dependent libraries. Go to the root directory of the project and execute php composer .phar install to download the dependent library files and store them in the vendor folder. There will also be an additional composer.lock lock file. Every time we need to install the required Yii2 plug-in, open composer.json and find "require" as follows:
"require": { "php": ">=5.4.0", "yiisoft/yii2": "=2.0.10", "yiisoft/yii2-bootstrap": "*", "yiisoft/yii2-swiftmailer": "*", "qiniu/php-sdk":"*", "dmstr/yii2-adminlte-asset":"2.*", "2amigos/yii2-file-upload-widget": "~1.0", "mdmsoft/yii2-admin": "=2.7", "yiisoft/yii2-jui": "=2.0.6", "linslin/yii2-curl": "*", "bower-asset/jquery": "1.12.*@stable", "bower-asset/layer": "3.*", "bower-asset/jquery-cookie": "1.4.*", "wdteam/yii2-webuploader": "*" },
Add one in it, and then execute php composer.phar update (update will update everything , if you only want to update the newly added plug-in, execute php composer.phar update foo/bar).
This is just one use of Composer in Yii2. It also has many commands. You can refer to the official website of Composer. As for the Yii2 plug-ins, I will sort out the commonly used plug-ins for everyone to use in the future.
The above is the detailed content of About the use of Composer in Yii2. For more information, please follow other related articles on the PHP Chinese website!