我想我解决了。
我发现可能会发生碰撞FCPATH . 'vendor'
自动加载和 APPPATH 。 “核心”类自动加载。如果您尝试从以下位置扩展您的控制器CI_
or MY_
前缀核心类我确信这会起作用。另一方面,如果您尝试使用不以CI_
or MY_
或者无论您配置什么,您都无法从供应商目录中找到所需的类。
我尝试了一下,发现如果您更改配置文件中使用的代码以自动加载核心类,它就可以工作。
你可以使用
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;
}
}
}
我将该文件替换为这个文件:
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目录。如果您没有其他供应商依赖项,请使用新创建的依赖项执行此操作composer.json
文件位于旁边index.php
包含以下代码的文件:
{
"require": {
"omnipay/omnipay": "~2.0"
}
}
2.将控制台导航到项目的根文件夹,其中还包含新创建的 json 文件。
3.启动命令composer install
4.在应用程序启动之前包含 Composer 自动加载文件。执行此操作的一种方法是在接近结束时index.php
文件,只是before line
require_once BASEPATH.'core/CodeIgniter.php';
,输入下一个代码:
require_once __DIR__.'/vendor/autoload.php';
5.在......的最后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);
}
}