0
Good morning. I have a webservice made on slimPHP . I have a class called control, and he belongs to the namespace controllers, it works normally without problems , but there arose the need to import a class for PDF manipulation , so that when I give the error include it , saying that it did not find the requested class. Does anyone know what it might be ? Follow the class.
<?php
namespace controllers {
include "fpdf/fpdf.php";
class Control {
//Atributo para banco de dados
private $PDO;
/*
__construct
Conectando ao banco de dados
*/
function __construct() {
$this->PDO = new \PDO('mysql:host=localhost;dbname=infoged', 'root',
'*******'); //Conexão
$this->PDO->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); //habilitando erros do PDO
}
public function PDF($romaneio) {
$pdf = new \fpdf\FPDF("P", "pt", "A4");
$pdf->AddPage();
}
}
}
Error:
<b>Fatal error</b>: Class 'fpdf\FPDF' not found in
<b>C:\xampp\htdocs\infoged\services\controllers\Control.php</b> on line
<b>142</b>
Archive start FPDF
define('FPDF_VERSION', '1.81');
class FPDF {
protected $page; // current page number
protected $n; // current object number
protected $offsets; // array of object offsets
protected $buffer; // buffer holding in-memory PDF
protected $pages;
.....
}
I believe that if you post the error that gives, it will help quite young.
– Bruno
Beauty , posting!
– Marlon Castro
It is very likely that the error is why you made the
includewithin thenamespace, including the FPDF classes in it, while you try to access the class in thenamespace \fpdf. Try to give theincludebefore thenamespace.– Woss
When I give the include before the namespace it returns me this error.
<b>Fatal error</b>: Namespace declaration statement has to be the very first statement in the script in– Marlon Castro
What do you have inside the fpdf.php file? Could you just post the class startup in this file please?
– Bruno Rigolon
So take those
{}ofnamespace.– Woss
Bruno posted it. Anderson I’ll take the test without the keys .
– Marlon Castro
When I put the keys out, he made another mistake. Although I still think it’s an error related to namespace or include, because if I give a include in another normal class this package works perfectly. The mistake now eh :
<strong>Message:</strong> Constant FPDF_VERSION already defined– Marlon Castro