Search code examples
slimslim-3

Returning Route Parameter in a page in SLIM 3


i a, having a link which sends public to view timeline of a specific user by passing variable in route.

<a href="<?php echo $baseLocation ?>/bnb-details/<?php echo $row['username']?>" >View</a>

and my route is defined as:

$app->get('/bnb-details/{name}', function (Request $request, Response $response, $args) {
include_once('bnb-details.php');
return $response; });

how can i pass the {name} args in the bnb-details.php ??

any kind of help would be appriciated.


Solution

  • you can use like this : you should pass parametere from args to variable

    $app->get('/bnb-details/{name}', function (\Slim\Http\Request $request, \Slim\Http\Response $response, $args) {
        $name = $args['name'];
        include_once('bnb-details.php');
        return $response;
    });
    

    then use

    echo $name;
    

    in bnb-details.php