I\'m trying to add omnipay in CodeIgniter (version 2.2.4) I followed the instructions in installing composer using this link:https://philsturgeon.uk/blog/2012/05/composer-wi
I think I solved it.
I have found that there could be collision of FCPATH . 'vendor'
autoloading and APPPATH . 'core' class autoloading. If you try to extend your controller from CI_
or MY_
prefixed core class I am sure that would work. In other hand, if you try to use core class that doesn't start with CI_
or MY_
or whatever you configured you couldn't find wanted class from vendor direcory.
I played around and found that if you would change the code used in config file for autoloading core classes it works. You could use
function __autoload($class)
{
if(strpos($class, 'CI_') !== 0)
{
include_once( APPPATH . 'core/'. $class . EXT );
}
}
or
function __autoload($class) {
if (substr($class,0,3) !== 'CI_') {
if (file_exists($file = APPPATH . 'core/' . $class . EXT)) {
include $file;
}
}
}
I swapped that file for this one:
spl_autoload_register(function ($class) {
if (substr($class,0,3) !== 'CI_') {
if (file_exists($file = APPPATH . 'core/' . $class . EXT)) {
include $file;
}
}
});
Just tested and it is working.
1. Download omnipay to root/vandor directory. If you don't have other vendor dependencies, do this with newly created composer.json
file located next to index.php
file with next code:
{
"require": {
"omnipay/omnipay": "~2.0"
}
}
2. Navigate console to root folder of your project that also include newly created json file.
3. Start command composer install
4. Include composer autoload file before application boot. One way for doing this is near the end of the index.php
file, just before line
require_once BASEPATH.'core/CodeIgniter.php';
, put next code:
require_once __DIR__.'/vendor/autoload.php';
5. At the end of APPPATH . 'config/config.php'
file, put this snippet to use core classes as well:
spl_autoload_register(function ($class) {
if (substr($class,0,3) !== 'CI_') {
if (file_exists($file = APPPATH . 'core/' . $class . EXT)) {
include $file;
}
}
});
6. In your controller at the beginning of the file before class is defined use needed vendor classes: