Class not found trying to integrate TCPDF |
Following the instructions here: https://forum.codeigniter.com/thread-754...#pid377974
I setup TCPDF, but upon running I am getting an error. As best I can tell I followed the instructions exactly (except for a slight name change). What am I missing? Unzipped the file downloaded from GitHub into App/ThirdParty/TCPDF Added a file (SBPdf.php) into App/Libraries: PHP Code: <?php Then in my controller I call it: PHP Code: public function testpdf() At that point I was getting an error: 'Class "App\Controllers\Admin\SBPdf" not found' I then added this to my controller (app/Controllers/Admin/Services.php), which got me closer, I think: PHP Code: use App\Libraries\SBPdf; But this produces an error of: 'Class "App\ThirdParty\TCPDF\Tcpdf" not found' error. Feel like I am missing something obvious as others have said it just works, so... Help!
Read this one also FIXED.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(09-02-2021, 04:34 AM)InsiteFX Wrote: Read this one also FIXED. Not sure I understand. I don't see anything in that post about the Class not being found.
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; 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 = [ 3. Import the library into your controller. PHP Code: <?php The easy way 1.Install the library with composer Code: composer require tecnickcom/tcpdf 2. Import the library into your controller. PHP Code: <?php
(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. 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! ![]() So your second solution is what I did and it worked. Thanks for replying! Us newbies appreciate it!
|
Welcome Guest, Not a member yet? Register Sign In |