CodeIgniter Forums

Full Version: Trying to use a barcode library with Composer and CI4
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi

I could successfuly install (in a CI4 install in subfolder) the following libraries with Composer: dompdf and guzzlehttp
Then, I use both in the Controller, etc.

Code:
...
...
use Dompdf\Dompdf;
use GuzzleHttp\Client;
...
...
$client = new \GuzzleHttp\Client(['http_errors' => false]);
$dompdf = new Dompdf();
...
...

But I cannot make the same with the following one:

https://github.com/picqer/php-barcode-generator

I've installed with this
Code:
composer require picqer/php-barcode-generator

Then I use with
Code:
use Picqer\Barcode;
use Picqer\Barcode\BarcodeGeneratorPNG;

But when I try to use it, CodeIgniter does not find it
Code:
$generator = new Picqer\Barcode\BarcodeGeneratorPNG();
Class 'App\Controllers\Picqer\Barcode\BarcodeGeneratorPNG' not found

I've checked the "vendor/composer/autoload_psr4.php" file to see the namespaces.

Any suggestions ?

Thanks a lot
its also use Exceptions.

So you would also have to load the Exceptions before the other two classes.

It's also using Imagick for drawing the barcodes.
(06-26-2020, 03:32 AM)InsiteFX Wrote: [ -> ]its also use Exceptions.
So you would also have to load the Exceptions before the other two classes.

Where did you notice/find that? and how do you know that the Exception classes should be load before the others?

(06-26-2020, 03:32 AM)InsiteFX Wrote: [ -> ]It's also using Imagick for drawing the barcodes.

Yes, I've both with gd correctly setup

Thanks again
PHP Code:
$generator = new \Picqer\Barcode\BarcodeGeneratorPNG(); 

It miss \
(06-26-2020, 05:52 AM)Paradinight Wrote: [ -> ]
PHP Code:
$generator = new \Picqer\Barcode\BarcodeGeneratorPNG(); 

It miss \

Wow, it was just that ... It worked!
Thanks @Paradinight
(06-26-2020, 05:59 AM)kabeza Wrote: [ -> ]
(06-26-2020, 05:52 AM)Paradinight Wrote: [ -> ]
PHP Code:
$generator = new \Picqer\Barcode\BarcodeGeneratorPNG(); 

It miss \

Wow, it was just that ... It worked!
Thanks @Paradinight

If you use "use" you can do:

use Picqer\Barcode\BarcodeGeneratorPNG;

$generator = new BarcodeGeneratorPNG();

or


use Picqer\Barcode\BarcodeGeneratorPNG as AnOtherName;

$generator = new AnOtherName();
(06-26-2020, 06:19 AM)Paradinight Wrote: [ -> ]If you use "use" you can do:

use Picqer\Barcode\BarcodeGeneratorPNG;
$generator = new BarcodeGeneratorPNG();

or

use Picqer\Barcode\BarcodeGeneratorPNG as AnOtherName;
$generator = new AnOtherName();

Great! that worked fine. Thanks again for the useful tips
If you look at the barcode class files you will see what they are loading.