A
A
Alexey Ukolov2014-08-21 09:09:36
symfony
Alexey Ukolov, 2014-08-21 09:09:36

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

1 answer(s)
D
DYPA, 2014-08-21
@alexey-m-ukolov

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 question

Ask a Question

731 491 924 answers to any question