The easiest way to add composer into Codeigniter 3

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

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

Web development
22nd Jul 2018 02:02:56 AM
PHP CodeIgniter


ShareurCodes is a code sharing site for programmers to learn, share their knowledge with younger generation.