1

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_party\vendor\'; folder. So in my config file I have the following line:

$config['composer_autoload'] = APPPATH . 'third_party\vendor\autoload.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();
}

This results in the following error:

Message: Class 'WebChemistry\Invoice\Data\Company' 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?

Dennis
  • 3,044
  • 2
  • 33
  • 52

2 Answers2

2

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();
    }

}
Anfath Hifans
  • 1,588
  • 1
  • 11
  • 20
  • I have run it and check and i have seen to many deprecated error message from the library file : `Replace deprecated Nette\Object with trait Nette\SmartObject ` – Anfath Hifans May 06 '18 at 06:59
1

You should not do anything with vendor directory unless you know what you're doing. If you want to change directory where Composer installs dependencies, you can do this by setting vendor-dir in composer.json config:

{
    ...
    "config":{
        "vendor-dir": "third_party/vendor"
    }
}
rob006
  • 21,383
  • 5
  • 53
  • 74