CodeIgniter + omnipay installation

六月ゝ 毕业季﹏ 提交于 2019-12-03 20:26:42

问题


I have used ci-merchant before but from everything see that the "V2" of it is now omnipay. I use codeigniter and i'm struggling to get even the example to work.

I have installed omnipay no problems and in my controller have the following:

use Omnipay\Common\GatewayFactory;
class Homepage extends BC_basecontroller {

public function index()
{
    $gateway = GatewayFactory::create('PayPal_Express');
    $gateway->setUsername('adrian');
    $gateway->setPassword('12345');
}
}

Which is the example here: https://github.com/adrianmacneil/omnipay

However I get the error:

PHP Fatal error:  Class 'Omnipay\Common\GatewayFactory' not found in......

Does anyone know how to get it to work in CI?


回答1:


I'm not sure how you installed Omnipay, but you need to use Composer to load the classes before you can use them.

So following the Omnipay installation instructions, add this to a composer.json file in your root directory:

{
    "require": {
        "omnipay/omnipay": "*"
    }
}

Then install the files:

$ curl -s http://getcomposer.org/installer | php
$ php composer.phar update

Now, if you are using CodeIgniter you will need to set it up to include the composer autoloader. Basically, just add this line to the top of your index.php file:

require_once __DIR__.'/vendor/autoload.php';

There is also a tutorial on using Composer with CodeIgniter here which you may find helpful: http://philsturgeon.co.uk/blog/2012/05/composer-with-codeigniter




回答2:


I had the same error and fixed it by loading vendor/autoload.php before application/core/CodeIgniter.php



来源:https://stackoverflow.com/questions/17081800/codeigniter-omnipay-installation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!