Composer in php with example of how to use it in Codeigniter project.
Last night i was studying about composer in php, It works great like npm package.json,
Now time to start your next php application with composer.
What is composer?
Composer is a tool for dependency management in PHP. It allows you to declare the dependent libraries your project needs and it will install them in your project for you.
Form https://getcomposer.org
Now time to taste composer
Create your project directory “MyNewProject”
Now go to your project directory using terminal
Now time to install composer command line just type
curl -sS https://getcomposer.org/installer | php |
Note: Make sure curl is already installed in your system
Now create composer.json file under your project directory
composer.json
{ "require": { "monolog/monolog": "1.2.*" } } |
Finally install dependencies using below command
$ php composer.phar install |
This will create a vendor directory in your root folder of your project.
vendor directory have all the libraries which you are going to use in your projects
For Exp: Using below steps you can use composer in your next codeigniter project.
Add autoload.php to your Codeigniter’s index.php before require_once BASEPATH.’core/CodeIgniter.php’;
require_once('./vendor/autoload.php'); |
Another example to install composer with cakephp
If you are going to installing and configure cakephp using composer then your composer.json file will be
composer.json
{ "name": "example-app", "require": { "cakephp/cakephp": "2.6.*" }, "config": { "vendor-dir": "Vendor/" } } |
and install composer
$ php composer.phar install |
For more detail you can see official document of cakephp with composer.
http://book.cakephp.org/2.0/en/installation/advanced-installation.html
Hope this will help you to understand composer in php 🙂