M
M
MarEeeeeee2020-10-27 21:02:20
Yii
MarEeeeeee, 2020-10-27 21:02:20

Why doesn't require work?

My code snippet where I am trying to use the fpdf library to work with pdf files. The thing is, I am getting the following error Class 'app\models\FPDF' not found. If you refuse to use the namespace, everything becomes fine, but my main code is built on this. How to get around this problem?

namespace app\models;

use Yii;
use yii\base\Model;

require('.\..\vendor\setasign\fpdf\fpdf.php');
$envelope = __DIR__ .'\images\konvert-6.jpg';
$img = ImageCreateFromJPEG($envelope);
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Image($envelope,60,30,90,0);
$pdf->Output();

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
krundetz, 2020-10-27
@krundetz

composer require setasign/fpdf:^1.8
in the console in the code For review
use setasign\Fpdf

T
toxa82, 2020-10-27
@toxa82

require works for you, otherwise it would swear at it. You are calling $pdf=new FPDF(); being in app\models namespace, you should call $pdf=new \FPDF(); or specify the name of the FPDF class with namespaces if it has them

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question