Use of FPDF library in CI4 |
Hello guys,
As I need fpdf in my project, I have installed it thru seatsign/fpdf found in packagist.org, using : composer require setasign/fpdf:^1.8 It is now present in the vendor\setasign\fpdf directory of my app To get it in my project, I have put a file MyFpdfClass.php in \APP\Libraries containing : <?php namespace App\Libraries; use \setasign\fpdf\fpdf; [...] class MyFpdfClass extends Fpdf { but the call in controller $t = new MyFpdfClass() send an error : Class "setasign\fpdf\fpdf" not found APPPATH/Libraries/MyFpdfClass.php at line 13 How can I set the "use" so that the library is found ? Is it a problem with autoloader not correctly set ? Thanks for your help Eric
Use modern IDE for development. Have autoimport namespaces
PHP Code: <?php
if you integrated seatsign/fpdf using composer, then to use the classes of that package in a controller it would be in the form of :
Code: use fullNamespaceName\classname //Youwant to use To get the namespace open up one of the classes with a text editor. For instance i used composer to integrate PHPMailer into CI4 opening up one of the classes i saw they used the namespace Code: PHPMialer\PHPMailer I noticed there were few classes , of which one class of PHPMailer might need to use another, so in my controller, where I will instantiate i wrote Code: use PHPMailer\PHPMailer\PHPMailer; then in the same controller to instantiate it was just : Code: $mail = new PHPMailer(true); Now if you used composer to install , CI should know exactly where classes are , via autoload. So you should have to shift things about or mess with autoload class. Previously i manually put in PHPMailer at root level ; in that case I did have to make use of autoload.php and the section Code: public $psr4 = [ The point as i understand it is that with composer , if the classes integrated in vendor , DO HAVE a namespace in the classes, then you shouldn't have to do anything excpet make use of "use"
I have found that mPdf is much easier to configure and to use. Install via composer.
Especially where you already have the output in html/css and just need to output as a pdf. Give it a look. The docs can be found here https://mpdf.github.io/
i got this one working on one of my old sites : https://packagist.org/packages/tecnickcom/tcpdf
I want use fpdf in my project CI4.. how i can do this step by step? How include it as thirdparty?!
<?php namespace App\Controllers\Purchase; namespace App\ThirdParty\fpdf; use CodeIgniter\Controller; use FPDF; ?> and how build the controller to call fpdf methods?! $pdf = new PDF(); $pdf->AddPage(); thanks |
Welcome Guest, Not a member yet? Register Sign In |