Slim: How can I request for URI parameters when using a controller function in route

Created on 20 Jun 2017  路  2Comments  路  Source: slimphp/Slim

My Route is:

$app->get('/api/courts/{id}/{date}','\App\Controllers\AvailabilityController:getCourtAvailability'){
$id=$request->getAttribute('id');
$date=$request->getAttribute('date');
return json_encode();
};

I know that my way is incorrect. Please tell me the correct method as I cannot find any solution

Most helpful comment

thanks for helping @tflight !! 馃憤 馃挴 馃

All 2 comments

See Route Placeholders and Container Resolution in the docs.

The route:

$app->get('/api/courts/{id}/{date}', '\App\Controllers\AvailabilityController:getCourtAvailability');

Then in your controller:

public function getCourtAvailability($request, $response, $args) {
    $id = $args['id'];
    $date = $args['date'];
    return $response; // your real response
}

thanks for helping @tflight !! 馃憤 馃挴 馃

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alexweissman picture alexweissman  路  38Comments

l0gicgate picture l0gicgate  路  83Comments

l0gicgate picture l0gicgate  路  50Comments

l0gicgate picture l0gicgate  路  31Comments

codeguy picture codeguy  路  43Comments