I\'m using the requests library (http://requests.ryanmccue.info/) for PHP.
I installed composer and added the following Json configuration in composer.json
The asker doesn't say what version of Codeigniter they are using, but for 3.x I don't think the accepted answer is the correct way to do it. CI Autoloading documentation here: https://www.codeigniter.com/user_guide/general/autoloader.html
In 3.x, first you want to turn on Composer autoloading in the application/config/config.php file:
$config['composer_autoload'] = true;
Note this comment in config.php, it may be very important. More on this below.
// Enabling this setting will tell CodeIgniter to look for a Composer
// package auto-loader script in application/vendor/autoload.php.
Then if you have this in your composer.json file:
"require": {
"rmccue/requests": ">=1.0"
},
"autoload": {
"psr-0": {"Requests": "library/"}
}
(there is probably a lot more stuff in your file, I edited it out for brevity)
Once you run composer update, you should end up with Requests working via Composer autoloading, so this should work without the need to specifically load vendor/autoload.php, which you want to avoid.
Requests::register_autoloader();
NOTE:
I have multiple installs of Codigniter on my server, and I followed the instructions as prescribed. In my case the vendor directory and composer.json were installed at the same level as the application folder, not in the application folder, therefore enabling Composer autoloading didn't work. If this happens to you, you have 2 choices:
Anyway, hope this helps anyone who might get stuck with this - I burned a good 2 hours trying to resolve the issue before I finally realized that my vendor directory wasn't where CI was looking for it.