src/Controller/LandingController.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. class LandingController extends AbstractController
  7. {
  8.     /**
  9.      * @Route("/" , name="index_landing_new")
  10.      */
  11.     public function landingAction(Request $request) {
  12.         $localeAvailable = array( 'en''fr''ar');
  13.         $localeUser substr($request->getPreferredLanguage(), 02);
  14.         $localeApp $request->attributes->get('_locale');
  15.         //Redirect to the good locale page
  16.         //only if the locale user is on our manager locale and it is not the current locale of the application
  17.         if(in_array($localeUser$localeAvailable) && $localeApp!=$localeUser){
  18.             return $this->redirect($this->generateUrl("app_front_main_index", array('_locale' => $localeUser)));
  19.         }
  20.         return array();
  21.     }
  22. }