easiest way to add composer into Codeigniter 3

The easiest way to add composer into Codeigniter 3

In this post we will show you The easiest way to add composer into Codeigniter 3, hear for The easiest way to add composer into Codeigniter 3 we will give you demo and example for implement.



The composer is a dependency manager for PHP. It helps you to easily integrate  3rd party libraries in your projects. Adding composer to your CodeIgniter project is very easy. Before starting the steps for composer integration in CodeIgniter you need to make sure that composer is installed in on your computer. You can download composer from the following link Download Composer. Composer installation procedure is pretty much straight forward and I don't think that I need to explain that here.
Now the steps for adding composer to your CodeIgniter project
  • First copy and paste composer.json file in the project folder to the application folder
  • Second in the config.php file $config['composer_autoload'] = TRUE;
That is it, you successfully integrated composer in your CodeIgniter project. For better clarification, i will show you an example how to install mpdf using composer.
  1. Open cmd and direct to application folder
  2. Inside application directory Type composer require mpdf/mpdf
Now a vendor folder will be created inside application folder and inside vendor folder you can see all your packages downloaded by composer.
Now since you autoloaded composer now you can just use the code given by mpdf official manual like
function m_pdf(){

$mpdf = new mPDF();

// Write some HTML code:

$mpdf->WriteHTML('Hello World');

// Output a PDF file directly to the browser
$mpdf->Output();
  
}

Remember you don't need to type require_once APPPATH.'/vendor/mpdf/mpdf/mpdf.php'; since you already autoloader composer.
If you not prefer to autoload composer you must type require_once APPPATH.'/vendor/mpdf/mpdf/mpdf.php' at the beginning of each controllers where you use the mpdf vendor libraries.
Now you can easily integrate thousands of latest open source PHP libraries in just one click. You can browse all packages composer has by visiting https://packagist.org/

Hope this code and post will helped you for implement The easiest way to add composer into Codeigniter 3. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve onlincode. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs us

Comments