All!
I just see that symfony2 router doesn't use the host part of the uri. I need to separate COUNTRY as third subdomain and locale as first element in route path
http://{country}.mysite.com/{_locale}/myaction, i.e.
en.mysite.com/en/action --- english companies & english language
de.mysite.com/ru/action --- deutschland companies & russian language
ru.mysite.com/uk/action --- russian companies & ukrainian language
The problem solved with service like below:
-- config.yml
services:
kernel.listener.subdomain_listener:
class: Acme\DemoBundle\Listener\SubdomainListener
tags:
- { name: kernel.event_listener, event: kernel.request, method: onDomainParse }
-- SubdomainListener.php
<?php
namespace Acme\DemoBundle\Listener;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\Event;
class SubdomainListener
{
public function onDomainParse(Event $event)
{
$request = $event->getRequest();
$session = $request->getSession();
// todo: parsing subdomain to detect country
$session->set('subdomain', $request->getHost());
}
}
BUT... The question is: how It's possIble (right wAy) to implement AUTH process between several subdomains transparently only once ??
user logged via en.mysite.com/{_locale}/...
user going to de.mysite.com/{_locale}/... but system knows about him(her) and doesn't ask the login/password credentials again
Does anybody help me ? Thanks for advance! Certified Senior Oracle Developer/DBA
You can easily accomplish this by setting the correct cookie domain. That way all subdomains will be able to access the cookie that identifies your users' session.
What you want to do is set your cookie domain to: .mysite.com
(yes, a dot at the beginning).
To do that, set the following configuration in your config.yml
file:
framework:
session:
cookie_domain: .mysite.com
Note: If you're using remember_me from the security component, you'll probably want to set the domain on the remember_me
section of your firewall.
Addendum: In Symfony 2.0, the relevant setting was 'domain'. It was deprecated in 2.1.