Answer the question
In order to leave comments, you need to log in
How to describe checking two related parameters in routing?
There are several countries on the site, each country has several available languages.
URLs look like this: '/{country_code}/{lang_code}' You can specify
restrictions for country and language codes through requirements, but how to make sure that after a specific country code there is a code for one of several languages available for it, and not just any language code from the list?
Answer the question
In order to leave comments, you need to log in
write EventSubscriber
<?php
namespace XXXBundle\EventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class LocaleSubscriber implements EventSubscriberInterface
{
public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
//дальше в request находим свой роут и параметры
//потом делаем проверки
}
public static function getSubscribedEvents()
{
return [
KernelEvents::REQUEST => ,
];
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question