One page per article

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

Topics covered: Route parameterLinkMethod

On the front page, you only read the beginning of each article. The villagers want the rest! Each article will get its own page, at the address /articles/ followed by its slug.

Your mission

  1. Declare the route GET /articles/{slug}. The curly braces mark the variable part of the address: its handler receives an array $parametres (parameters), and $parametres['slug'] is 'the-pumpkin-festival' for /articles/the-pumpkin-festival. Find the article with Redaction::article($parametres['slug']).
  2. The article page: a <main class="lecture"> with the full article, returned by $article->versHtmlComplet() (the nephew added it to Article), and a link <a class="retour">← Back to the front page</a> to the front page. Everything is laid out by Page::rendre(), and the browser tab shows “article title — The Saint-Glinglin Gazette”.
  3. In src/Contenu/Article.php, on the front page, the title of each article becomes a link to its page.

Build every address with Url::vers() (to), never hard-coded.

Reminder

{slug} is a route parameter: it accepts any text without a /, which FastRoute puts in $route[2], the array passed to the handler. A method of the class can read its private properties: versHtmlComplet() is allowed to use $this->texte, but code outside the class is not.