I've followed this article: http://philsturgeon.co.uk/blog/2012/05/composer-with-codeigniter
But I get Fatal error: Class 'Buzz\Browser' not found
.
What is missing from his post?
My controller or application isn't namespaced. I was hoping to just be able to use that one package in one controller's action in a non-namespaced framework.
Well in Codeigniter3.x you can easily do that by going into the application/config/config.php and look for this line
Make sure you set it to TRUE and right after it you require_once this:
So you get something like this:
Just make sure you have your vendor folder in the application folder and you are good to go.
I recently found out that you can just set $config['composer_autoload'] = TRUE; and put your vendor folder in the application folder and that's it.
There are two ways you can autoload the class file which is required using composer.
Add below line in index.php in the root directory.
Or autoload directly in the controller where you want to use.
EDIT: Damn, I just said pretty much exactly the same thing as @Tjorriemorrie
If you've followed all the other directions correctly, all you need to do is add the following code near the very the end your index.php file:
...just make sure you slot it in before the CodeIgniter Bootstrap file is called:
For CodeIgniter 3.x and composer, it's suggested to just set
$config['composer_autoload']
toTRUE
or a custom path inapplication/config/config.php
.It seems that CI assumes the
vendor
directory is within theapplication
directory. That wasn't my case. I did the following:$config['composer_autoload'] = 'vendor/autoload.php';
I'm using Kenjis codeigniter composer package, and it puts the vendor directory off of the root. Since there is no predefined constant (that I know of) for the root, I used the following:
Credit to @jmadsen
This is possible by just getting the order of loading correct: