Ayush28
Ayush28

Reputation: 379

Paasing URI parameters in the route when using controller function in Slim framework

How can I pass URI parameters in the route when using controller function?

For example:

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

Is the above method correct ??

Upvotes: 0

Views: 472

Answers (1)

ekans
ekans

Reputation: 1714

By default, arguments named in route are passed in function as third argument (an array), so in your AvailabilityControler, they must be a function named getCourtAvailability like this :

getCourtAvailability ($request, $response, $args){
    $id = $args['id']; // because id is set in route
    $date = $args['date']; //because date is set in route
    // your treatement here
}

Hope I help ;)

Upvotes: 3

Related Questions