user3676604
user3676604

Reputation:

Symfony One Application - Multiple Subdomains

i want to achieve the following in a Symfony 3 application. Lets say i have 2 restricted areas for users and admins.

Users should be able to access their area on user.mydomain.com while admins should go to admin.mydomain.com.

I have a question for it, hope someone can answer them.

Both would have some same routes like /login, /register, and /dashboard.

Is it possible to be achieved in one single application?

Like if a user goes to user.mydomain.com/login he should be able to login as a user not as an admin.

While an admin goes to admin.mydomain.com/login should only be able to be logged in as admin.

I hope its clear what i mean and that someone can post some links to docs or tutorials or an giving example.

Would be really thankful for instructions.

Upvotes: 1

Views: 2133

Answers (2)

Michał G
Michał G

Reputation: 2292

You can use different path/domains in routing , so i wolud try to create listener and connect it (using events) to main request

In this listener i would chceck who is logged , and redirect it to correct route

Some years ago i was created listener to change path ti image cache ( liipimaginebundle) , a know that this is not the same , but it can give you idea

https://gist.github.com/poznet/842ae820a230ba982a66f854549b0e2b

Upvotes: 0

Jenne
Jenne

Reputation: 883

I think your looking for http://symfony.com/doc/current/routing/hostname_pattern.html

Your still going to need to check for each user or admin case. However it is obviously not possible to know if a user is an admin before logging in and actually checking their roles, so if it was up to me id just make a common login (which you could show on both domains) and allow access (redirect after login) based on roles to their hostname equivalents.

Regards

Upvotes: 2

Related Questions