Created
May 24, 2021 11:47
-
-
Save SilentKernel/0b898695a598823ed75f9a49bc7955bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Controller; | |
class BlogController extends AbstractController | |
{ | |
// ... ça va bien ? | |
public function oneArticle(Request $request, EntityManagerInterface $em, string $categorySlug, string $articleSlug) | |
{ | |
// I///ci votre logique de base pour retrouver votre article | |
// .. | |
// Et si on l'a pas trouvé ALORS | |
if ($article === null) { | |
// On cherche l'article via la méthode crée juste avant | |
$articleOldSlug = $articleRep->getByOldSlug($articleSlug); | |
if ($articleOldSlug !== null){ | |
// On a trouvé l'article ? on redirige en 301 (attention, 301 = permanant, je vous invite a regarder ce que celà implique) | |
return $this->redirectToRoute('blog_single_article', ['articleSlug' => $articleOldSlug->getSlug(), 'categorySlug' => $articleOldSlug->getCategory()->getSlug()], 301); | |
} | |
throw new NotFoundHttpException("Article introuvable"); | |
} | |
} | |
// Le reste de votre SUPERBE controller | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment