How to pass variable in URL?

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
Almeida 3A
User
Posts: 85

How to pass variable in URL?

Post by Almeida 3A »

Hello,
In custom file I add an example page:
document_abc.php and you have to pass a variable like:
document_abc.php?pag=111.
The page "turns" DocumentoAbc, and when you click on the link: document_abc.php?pag=111 it gives an error: 404
Not Found
Route 'availability_imprimir.php' not found.

If anyone knows or has related topics I would appreciate it.


mobhar
User
Posts: 11736

Post by mobhar »

Since v2021, PHPMaker uses Routes to access the page, and not by php filename anymore. For more info, please read: Routing.


Almeida 3A
User
Posts: 85

Post by Almeida 3A »

very good,

I use the mPDF class for reporting, I know it is a 3rd party tool. I installed the new version for php8, I installed it with composer and it installed correctly, but when I launch it it always gives an error. I even tried other classes like tcPDF, but no solution.

If anyone has an idea I would appreciate it.

error: 'config_3a/testetcpdf/tcpdf' (include_path='C:\xampp8\php\PEAR')


mobhar
User
Posts: 11736

Post by mobhar »

You may post your code in that Custom File for more discussion.


arbei
User
Posts: 9389

Post by arbei »

You should check your "vendor" folder and see if you have "tecnickcom/tcpdf". If you have enabled the dompdf extension, you might already have it, otherwise you should add the package to your project, read Composer Packages. If your Custom File uses Include common files, then you don't need to include the TCPDF file yourself, you simply just use it. Otherwise you need to use a correct include path, the error you posted probably means that you included a wrong path.


Almeida 3A
User
Posts: 85

Post by Almeida 3A »

My project:
C:\xampp8\htdocs\scoppa2024

I installed my mmPDF class here:
C:\xampp8\htdocs\scoppa2024\config_3a

here is the class and vendor:
C:\xampp8\htdocs\scoppa2024\config_3a\mpdf
C:\xampp8\htdocs\scoppa2024\config_3a\vendor

I put the right way:
require_once 'config_3a/vendor/autoload.php';

To view the PDF in the browser:

<?php
// Includes Composer autoloader
require_once 'config_3a/vendor/autoload.php';

// Create a new mPDF instance
$mpdf = new\Mpdf\Mpdf();

// Add content to PDF
$mpdf->WriteHTML('<h1>Hello world!</h1>');

//Exit the PDF to the browser
$mpdf->Output('file.pdf', 'I');
?>

Show:
%PDF-1.4 % 3 0 obj <> /Contents 4 0 R>> endobj 4 0 obj <> stream x = @ ; l $g-h F 0 AE|^ ; f ʍ v o 4 D8 4 U ,+ = Ha, ]" R ){ 2#L F} /˂ ) 8 9 ^ " Ɍ6& w # endstream endobj 1 0 obj <> endobj 5 0 obj <> endobj 6 0 obj < > endobj 7 0 obj <> endobj 8 0 obj
...

To force the PDF to download:

<?php
// Includes Composer autoloader
require_once 'config_3a/vendor/autoload.php';

// Create a new mPDF instance
$mpdf = new\Mpdf\Mpdf();

// Add content to PDF
$mpdf->WriteHTML('<h1>Hello world!</h1>');

//Output the PDF to the browser forcing the download
$mpdf->Output('file.pdf', 'D');
?>

when it downloads: Error
Failed to load PDF document.


Any solution?


Almeida 3A
User
Posts: 85

Post by Almeida 3A »

Just a complement:
I install the mPDF class in the folder:
C:\xampp8\htdocs\mPDF

file :

<?php
// Include Composer autoloader
require_once 'vendor/autoload.php';

// Create a new mPDF instance
$mpdf = new \Mpdf\Mpdf();

// Add content to PDF
$mpdf->WriteHTML('<h1>Hello world!</h1>');

// Output the PDF to the browser
$mpdf->Output('arquivo.pdf', 'I');
?>

This works, but inside phpmaker it doesn't work as reported above.


arbei
User
Posts: 9389

Post by arbei »

  1. It depends on where you put your custom file (which affects the relative path of the include file), you better use DIR to include your 3rd party package if you must include it yourself. You better add Composer package to your project as said above (so you don't need to inlcude it yourself).
  2. If you can output the PDF file inline, then your path is correct, and you should be able to download it as well, it is not related to relative path, you should configure your php.ini and enable PHP error logging (since you did not use "Include common files" you cannot use PHPMaker debugging) and check the PHP error_log file. Also make sure your web server can serve "application/pdf" MIME type.

Post Reply