Welcome Guest, Not a member yet? Register   Sign In
Class not found trying to integrate TCPDF
#5

(09-02-2021, 11:06 AM)iRedds Wrote: You are copying code you don't understand and you get an error. And these are the basics of PHP.
PHP Code:
use App\ThirdParty\TCPDF\Tcpdf
This line is trying to import the class and

1. The class file must be reachable through the path App/ThirdParty/TCPDF/Tcpdf.php
2. The class must be in the specified namespace (App\ThirdParty\TCPDF).

If you haven't guessed yet, then the shared library will not have the App\ThirdParty\TCPDF namespace.
That's why you get your error.

There are 2 simple solutions.

CodeIgniter way

1. Unpack the library from github to ThirdParty/TCPDF
2. Change config App/Config/Autoload. 
Add the line to the $classmap property
PHP Code:
public $classmap = [
 
    'TCPDF' => APPPATH '/ThirdParty/TCPDF/tcpdf.php',
    ]; 

3. Import the library into your controller.
PHP Code:
<?php 
namespace Your\Controller\Namespace
use TCPDF;  
Now you can create an instance of the class.

The easy way

1.Install the library with composer
Code:
composer require tecnickcom/tcpdf

2. Import the library into your controller.
PHP Code:
<?php 
namespace Your\Controller\Namespace
use TCPDF;  

Totally admit I don't fully understand CodeIgniter's methodology, but trying to learn. The autoload part seems to be what would have been needed - but was missing from the previous posts instructions. With that said, About 30 minutes ago I dug into composer and how it works and installed TCPDF via composer. Lo and behold, it just worked! Smile Guess in the future I shouldn't be scared of composer (never used it before because I hadn't taken the time to figure what it does and how it impacts what I do).

So your second solution is what I did and it worked. Thanks for replying! Us newbies appreciate it!
Reply


Messages In This Thread
RE: Class not found trying to integrate TCPDF - by SoccerGuy3 - 09-02-2021, 11:12 AM



Theme © iAndrew 2016 - Forum software by © MyBB