Reputation: 1192
Hello fellow programmers,
(a bit of background)I'm building a Symfony 2 application for university Student accommodation, when our clients from the university side register with their details a subdomain is created, students belonging to a particular university can access the online accommodation service through this subdomain, there will be several universities that will be registered and each university will have their own subdomain and separate set of related-data/student-data that cannot be accessed from other universities.
(what i have already done) i managed to create a nice login and register pages and also managed to create subdomains by editing the hosts file (with file_put_contents() any better way to do this using symfony?) then i created a service that fetches the UniversityID from the parameters.yml, this way i can get university specific data since all tables have a universityID column.
should i create a script that runs before every thing is loaded that would dynamically update the UniversityID inside the parameters.yml based on the subdomain? what is the best practice for this
In conclusion, what i want from the community is,
1). i'm looking to use the Front controller to load the University Specific data, how do i load/set dynamic data using front controller and/or Kernel
2). how to create subdomains from dynamically without being platform (OS) specific
-thanks
Upvotes: 0
Views: 320
Reputation: 1941
In order to do this dynamically you can base your solution on the following tutorial: http://knpuniversity.com/screencast/question-answer-day/symfony2-dynamic-subdomains .
You have a University dataset, that holds the university name and the subdomain(maybe the name slug).
Then you create a event listener that on every request will parse the URL and extract the subdomain and fetch the university with that subdomain.
If you are using DoctrineBundle, you can create a Filter to filter your results by the current university.
Upvotes: 1