[英]Error in installing omnipay in CodeIgniter
我試圖在CodeIgniter(版本2.2.4)中添加omnipay,我按照以下說明使用此鏈接安裝作曲家: https ://philsturgeon.uk/blog/2012/05/composer-with-codeigniter/
但我有這個錯誤:
Fatal error: Uncaught exception 'Omnipay\Common\Exception\RuntimeException' with message 'Class '\Omnipay\PayPal Express\Gateway' not found' in C:\xampp\htdocs\testserver\vendor\omnipay\common\src\Omnipay\Common\GatewayFactory.php:105
Stack trace: #0 [internal function]: Omnipay\Common\GatewayFactory->create('PayPal Express')
#1 C:\xampp\htdocs\testserver\vendor\omnipay\common\src\Omnipay\Omnipay.php(103): call_user_func_array(Array, Array)
#2 C:\xampp\htdocs\testserver\application\controllers\Test.php(18): Omnipay\Omnipay::__callStatic('create', Array)
#3 C:\xampp\htdocs\testserver\application\controllers\Test.php(18): Omnipay\Omnipay::create('PayPal Express')
#4 [internal function]: Test->Pay()
#5 C:\xampp\htdocs\testserver\system\core\CodeIgniter.php(360): call_user_func_array(Array, Array)
#6 C:\xampp\htdocs\testserver\index.php(203): require_once('C:\xampp\htdocs...')
#7 {main} thrown in C:\xampp\htdocs\testserver\vendor\omnipay\common\src\Omnipay\Common\GatewayFactory.php on line 105
我已經遵循了這篇文章( CodeIgniter + omnipay安裝 )中的建議,但是他們的建議對我都不起作用。
我正在使用codeigniter 2.2.4和apache 5.4.19
誰能幫我解決這個問題?
我想我解決了。 我發現FCPATH . 'vendor'
可能發生沖突FCPATH . 'vendor'
FCPATH . 'vendor'
自動加載和APPPATH。 “核心”類自動加載。 如果您嘗試從MY_
CI_
或MY_
前綴的核心類擴展您的控制器,那么我肯定可以。 另一方面,如果您嘗試使用不是以CI_
或MY_
開頭的核心類,或者您配置的任何內容,都無法從供應商的目錄中找到想要的類。
我到處玩耍,發現如果您要更改配置文件中用於自動加載核心類的代碼,它會起作用。 你可以用
function __autoload($class)
{
if(strpos($class, 'CI_') !== 0)
{
include_once( APPPATH . 'core/'. $class . EXT );
}
}
要么
function __autoload($class) {
if (substr($class,0,3) !== 'CI_') {
if (file_exists($file = APPPATH . 'core/' . $class . EXT)) {
include $file;
}
}
}
我將該文件交換為該文件:
spl_autoload_register(function ($class) {
if (substr($class,0,3) !== 'CI_') {
if (file_exists($file = APPPATH . 'core/' . $class . EXT)) {
include $file;
}
}
});
剛剛測試,它正在工作。
1.將 omnipay下載到root / vandor目錄。 如果您沒有其他供應商依賴項,請使用index.php
文件旁邊的新創建的composer.json
文件執行以下操作:
{
"require": {
"omnipay/omnipay": "~2.0"
}
}
2.將控制台導航到項目的根文件夾,該文件夾還包括新創建的json文件。
3.開始命令composer install
4.在應用程序啟動之前包括composer自動加載文件。 一種執行此方法的方法是在index.php
文件的結尾附近,就在行之前
require_once BASEPATH.'core/CodeIgniter.php';
,輸入下一個代碼:
require_once __DIR__.'/vendor/autoload.php';
5.在APPPATH . 'config/config.php'
APPPATH . 'config/config.php'
文件,請將該代碼段也使用核心類:
spl_autoload_register(function ($class) {
if (substr($class,0,3) !== 'CI_') {
if (file_exists($file = APPPATH . 'core/' . $class . EXT)) {
include $file;
}
}
});
6.在定義類之前,在文件開頭的控制器中,使用所需的供應商類:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
use \Omnipay\Omnipay;
use \Omnipay\Common\GatewayFactory;
class Test extends Back_Controller
{
function __construct()
{
parent::__construct();
}
public function index()
{
var_dump(new Omnipay);
var_dump(new GatewayFactory);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.