Get parameter in route action custom files

I have a custom files name ‘print_pf.php’.

I use Routing Action to pass my parameter using this code

// Route Action event
function Route_Action($app)
{
    // Example:
    // $app->get('/myaction', function ($request, $response, $args) {
    //    return $response->withJson(["name" => "myaction"]); // Note: Always return Psr\Http\Message\ResponseInterface object
    // });
    // $app->get('/myaction2', function ($request, $response, $args) {
    //    return $response->withJson(["name" => "myaction2"]); // Note: Always return Psr\Http\Message\ResponseInterface object
    // });\


     $app->get('/PrintPf/{id}', function ($request, $response, $args) {
     
         $par_id = $args['id']; // Get the id from the route
         $response->getBody()->write($id); // Write the id to the response
         return $response; // Return the response
         
         })

}

I want to access the response - the parameter id in the content of the custom files
Here is my code in custom files

<?php

echo "Print Profile for ID: " . htmlspecialchars($par_id);

  
?>

The problem is: Unable to retrieve the $par_id

My url generate correct link and parameter: http://localhost/customsys/PrintPf/1

If you just want to output some content directly (without a view page), you should write your whole content to the response, not the just the $id.

If you want to use HTML content in a custom file (with a view page), you should use Custom File with Include Common Files enabled. To get a route value in the custom file you may use global function, e.g. Route("id").

Yes I included common files, still I was unable to show the content of the parameter ID un my custom files

here is my updated code:

<?php


$getid = Route("par_id");

echo "Print Profile for ID: " . htmlspecialchars($getid);
  
?>

Note that the argument of Route() is the argument name you defined in your route (i.e. "id" in your case), not the arbitrary variable name (e.g. $par_id) you use later.

Also, Route_Action server event and Custom File are two different approaches, they are not used as a combination. If you use Custom File, you should set your route as the Path (see the notes for details), not by server event.

So what will I do if I want to send parameter in my custom file (print_pf.php) and access or display the paramter in the custom files? Please give me sample. I do not much understand the documentation.

In the Row Rendered, I used custom button to send parameters to custom file (print_pf.php), here is my code

 $idno = $this->id->CurrentValue;

$this->prints->ViewValue = 
    "<a href='PrintPf/" . urlencode($idno) . "' target='_blank' class='btn btn-success'>
        <i class='fa fa-print'></i> Print
    </a>";

Now in the custom file, i want to retrieved and show the idno

As replied:

Thank you for assistance

Here is my generated link

http://localhost/customsys/PrintPf/2

I want to get the data : 2 in my custom file… How will I do it?

Why don’t you change that code to:

"<a href='PrintPf?id=" . urlencode($idno) . "'

And then in your Custom File, simply get the value of id as follows:

$the_id = Get("id");

Thank you. Thanks for the patience for entertaining our queries. God Bless. Wishing you excellent health