Sections online

Exercise 6 of 9 in chapter 5 · 150 XP · 3 objectives checked by tests

Topics covered: Route parameterEnumfrom()

Gaston only reads the weather, and Odette only reads the village fair. Each section will get its own page: /sections/weather, /sections/village-fair, /sections/news-in-brief. The name in the address is the value of the Rubrique (section) enum, the one you gave it in chapter 2.

Your mission

  1. Add a static method public static function articlesDe(Rubrique $rubrique): array (articles of) to Redaction, which returns the list of articles in that section. Like publications(), you call it on the class: Redaction::articlesDe(Rubrique::Meteo).
  2. Declare the route GET /sections/{nom} (nom: name): find the section with Rubrique::from(), then show an <h2 class="titre-rubrique"> with its label, and its articles inside <main class="articles">. The browser tab shows “label — The Saint-Glinglin Gazette”.
  3. On every article, the section label (<p class="rubrique">) becomes a link to the section's page.

Reminder

A backed enum (enum Rubrique: string) can find a case from its value: Rubrique::from('weather') gives Rubrique::Meteo, and ->value goes the other way. With an unknown value, from() throws an error: we'll deal with that in the next exercise.