0
What I need
I need to import the modified FPDF library to the project.
What I did
Code is below, but I created a folder "Libraries" inside "App" and put the library there (with the name FPDF.php), put in Aliasses the name of the class and its path, and include in composer.json
the path of the folder there in the classmap
. I also added namespace App\Libraries\FPDF;
in the FPDF.php file inside Libraries.
My folder and file structure
What happened
Well, it doesn’t take a genius to figure it out: he’s not finding class.
config app.php
'aliases' => [
...
...
'FPDF' => 'App\Libraries\FPDF',
Composer.json
"autoload": {
"classmap": [
"database",
"app/Libraries"
],
"psr-4": {
"App\\": "app/"
}
},
Homecontroller.php
public function gerarPdf() {
if (Input::has('numeroDocumento') && Input::has('mesReferencia') && Input::has('anoReferencia')) {
$fpdf = new FPDF();
$fpdf->AddPage();
$fpdf->SetFont('Arial','B',16);
$fpdf->Cell(40,10,'Hello World!');
$fpdf->Output();
exit;
}
else {
return redirect()->back()->with('message', 'Por favor, digite todos os campos !');
}
}
Added to your controller the
use App\Libraries\FPDF\FPDF
? In Laravel 5 the app folder is already autoload, no need to use the classmap– gmsantos
@gmsantos If I do so it gives Namespace declaration statement has to be the very first statement in the script. Need to remove something ?
– Allan Ramos
The namespace has to be the first thing in your file (right after the <php tag?)
– gmsantos
<?php namespace App Http Controllers; use View, Input, App Models Barcode, App Libraries FPDF; class Homecontroller extends Controller {
– Allan Ramos