How to use composer packages in codeigniter?
For CodeIgniter 3.x and composer, it's suggested to just set $config['composer_autoload']
to TRUE
or a custom path in application/config/config.php
.
It seems that CI assumes the vendor
directory is within the application
directory. That wasn't my case. I did the following:
$config['composer_autoload'] = 'vendor/autoload.php';
Credit to @jmadsen
This is possible by just getting the order of loading correct:
/*
* --------------------------------------------------------------------
* LOAD THE BOOTSTRAP FILE
* --------------------------------------------------------------------
*
* And away we go...
*
*/
// Composer Autoloader
require FCPATH . 'vendor/autoload.php';
require_once BASEPATH.'core/CodeIgniter.php';
/* End of file index.php */