在供应商文件夹codeigniter中找不到类 [英] Cannot find class in vendor folder codeigniter

查看:98
本文介绍了在供应商文件夹codeigniter中找不到类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 webchemistry 中的发票生成器.我使用 composer require webchemistry/invoice:^ 1.0 安装了此文件.

I am trying to use the invoice generator from webchemistry. I installed this with composer require webchemistry/invoice:^1.0.

我将此文件夹移动到了我的 APPPATH.'third_party \ vendor \'; 文件夹.所以在我的配置文件中,我有以下几行:

I moved this folder to my APPPATH . 'third_party\vendor\'; folder. So in my config file I have the following line:

$config['composer_autoload'] = APPPATH . 'third_party\vendor\autoload.php';

我的index.php文件(在根目录中)包含以下代码:

my index.php file (in root) contains this code:

include_once BASEPATH.'../application/third_party/vendor/autoload.php';

在我的控制器中,我尝试执行以下操作:

In my controller I am trying to do the following :

public function createInvoice()
{
    $company = new \WebChemistry\Invoice\Data\Company();
}

这将导致以下错误:

消息:找不到类'WebChemistry \ Invoice \ Data \ Company'

Message: Class 'WebChemistry\Invoice\Data\Company' not found

在我的IDE(PhpStorm)中,按住Ctrl键并单击公司",它可以正确解析并指向正确的文件.为什么PHP无法将其解析为正确的文件位置?

When in my IDE (PhpStorm) I ctrl + click on Company, it can resolve correctly and points to the correct file. Why can PHP not resolve this to the correct file location?

推荐答案

在开始时在控制器中添加文件include和以下代码

add the file include and following code in your controller at the start

$config['composer_autoload'] = false; // no need change this, make it default

<?php
require_once(APPPATH . '/third_party/vendor/autoload.php');
use \WebChemistry\Invoice\Data\Company as Company;

class Invoice extends CI_Controller {

    public function createInvoice(){
        $company = new Company();
    }

}

这篇关于在供应商文件夹codeigniter中找不到类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆