Recently while building my CMS in Symfony, I've run into a problem. I have 2 controllers, publicationcontroller
and contactcontroller
. In both controllers, an instance of the entity Page
is loaded whenever a corresponding slug matches. Below is the code:
class ContactController extends AbstractController
{
/**
* @Route("/{slug}", name="contact")
*/
public function index(PageRetriever $pageRetriever, $slug)
{
$page = $pageRetriever->getPage($slug);
return $this->render('contact/index.html.twig', [
'page' => $page
]);
}
}
class PublicationController extends AbstractController
{
/**
* @Route("/{slug}", name="publications")
*/
public function index(PageRetriever $pageRetriever, $slug)
{
$page = $pageRetriever->getPage($slug);
return $this->render('publication/index.html.twig', [
'page' => $page
]);
}
}
My problem is that both the content of publication and contact are loaded in the same template, depending on which controller is initialized first.
Does anyone here have an idea or some tips on how to load the proper template, depending on which slug is called?
Any hope is greatly appreciated