"symfony2 routing - route subdomains" Answer’s

0

This is my solution:

In the config.yml inside app dir add the following lines:

services:
   kernel.listener.subdomain_listener:
       class: AcmeDemoBundleListenerSubdomainListener
       tags:
           - { name: kernel.event_listener, event: kernel.request, method: onDomainParse }

Then create the class SubdomainListener.php as:

<?php

namespace AcmeDemoBundleListener;

use SymfonyComponentEventDispatcherEventDispatcher;
use SymfonyComponentEventDispatcherEvent;

class SubdomainListener
{
   public function onDomainParse(Event $event)
   {
       $request = $event->getRequest();
       $session = $request->getSession();

       // todo: parsing subdomain to detect country

       $session->set('subdomain', $request->getHost());
   }
}
Wednesday, March 31, 2021
 
nighter
answered 11 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :