For a future project, I’m looking for a way to manage multisites development with Symfony2. In fact, each site will be on a different subdomain but will works the same way ; only the style will changed a little.
The thing is : the authentication is common to all subsites, and is managed by the main site (www.mydomain.com). Each multisites will then have its own database.
Is it possible to do so with Symfony2 ? I know it’s possible to use multidomains, but I don’t how about the authentication system. Do you have ideas on how to proceed ?
Thanks !
Actually I’ve managed to do this in one of projects I’m working on.
It’s a bit tricky but once you understand the basic concept behind the symfony’s security layer it’s extremely easy to integrate into your existing project.
First off, be sure to read this: http://symfony.com/doc/current/book/security.html. I’d also recommend taking a look at the cookbook’s security section.
You won’t find a straight anwer in the manual but it helps to understand the code I’m going to paste here.
The basic idea is to share the session id across the subdomains.
Note: for the sake of space, I’ll be omitting the
useandnamespacetags in PHP. Don’t forget to import and specify appropriate namespaces.security_factories.yml:
config.xml:
And finally – the security.yml:
This is the simpliest and as neat as possible thing I could think of.
The only “misused” class here is the
SessionMatcherwhich only checks for the availbility of the session id in the session.Good luck, and feel free to ask question in the comments section. I know this can be pretty confusing at the beginning.