Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
815 views
in Technique[技术] by (71.8m points)

php - Cannot find class in vendor folder codeigniter

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

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

$config['composer_autoload'] = APPPATH . 'third_partyvendorautoload.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 WebChemistryInvoiceDataCompany();
}

This results in the following error:

Message: Class 'WebChemistryInvoiceDataCompany' not found

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 WebChemistryInvoiceDataCompany as Company;

class Invoice extends CI_Controller {

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

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...