Exercise 2 of 8 in chapter 1
· 100 XP
· 4 objectives checked by tests
Topics covered:Route parameter404
The menu is a hit. So much so that adventurers now want to know everything about each dish before ordering. Gorm wrote the list of dishes in the MenuController::PLATS constant (plats = dishes), each one identified by a URL identifier (the slug). Each dish has a nom (name), a description, a prix (price) and a specialite (specialty) flag.
Your mission
Add a /dish/{slug} route to MenuController, named app_plat, on the plat() method.
If the slug is not on the menu, return a 404: adventurers have no business ordering a grilled unicorn.
Otherwise, render the menu/plat.html.twig template: the dish name in the <h1> and in the page title, its description in <p class="description">.
Try /dish/elven-pie and /dish/grilled-unicorn in the preview's address bar.
Reminder
Symfony passes each route parameter to the method argument with the same name. AbstractController::createNotFoundException() creates the exception that produces a 404 page.