Page 1 of 1

How to pass variable in URL?

Posted: Sun Mar 31, 2024 8:47 am
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.


Re: migration 2018 to 2024, pass variable.

Posted: Sun Mar 31, 2024 10:19 am
by mobhar

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


Re: How to pass variable in URL?

Posted: Mon Apr 01, 2024 7:38 pm
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')


Re: How to pass variable in URL?

Posted: Mon Apr 01, 2024 8:24 pm
by mobhar

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


Re: How to pass variable in URL?

Posted: Mon Apr 01, 2024 10:00 pm
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.


Re: How to pass variable in URL?

Posted: Tue Apr 02, 2024 8:01 am
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?


Re: How to pass variable in URL?

Posted: Tue Apr 02, 2024 8:12 am
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.


Re: How to pass variable in URL?

Posted: Tue Apr 02, 2024 9:51 am
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.