How many adventurers?

Exercise 5 of 8 in chapter 1 · 120 XP · 4 objectives checked by tests

Topics covered: Query string#[MapQueryParameter]Validation

Saturday night, the Fellowship of the Ring showed up unannounced: nine adventurers, three tables, zero seats. Gorm wants people to be able to book. First step: a page that announces the table for the number of guests given in the address, for example /reservation?personnes=4 (personnes = people).

The reservation/index.html.twig template is ready: it expects a personnes variable.

Your mission

  1. Declare the /reservation route, named app_reservation, on ReservationController::index().
  2. Read the number of people from the query string (?personnes=…). Without the parameter, the table is for 2.
  3. Reject absurd values: only a number between 1 and 12, otherwise a 400 error (bad request).
  4. Add a link to the reservation page in the navigation.

Try it in the preview: ?personnes=5, ?personnes=0, ?personnes=dragon.

Reminder

Rather than reading $request->query and validating everything by hand, Symfony's attributes describe what the action expects: the framework takes care of converting and rejecting.