A
A
ADA M2017-07-06 08:00:15
Yii
ADA M, 2017-07-06 08:00:15

One site for 3rd level domains?

Please tell me how this functionality is implemented:
I’ll take the schools.by
site as an example. This site allows you to create subsites for schools that will have a 3rd-level domain school .schools.by
As I understand it, it’s impossible to create a separate site for each school every time, and the whole the functionality belongs to a single application that somehow handles requests from 3rd level domains.
Moreover, the following queries school .schools.by/teacher/id are used on the subsites of schools, and not in this form schools.by/ school /teacher/id.
How to implement something like this in Yii2? I am developing something like the above portal, where there will be information on the main 2nd level domain, and there will be separate subsites with the same functionality on 3rd level domains.
Working examples:
https://schools.by/sites (main site)
https://upk1.schools.by/ (subsite)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2017-07-06
@webinar

Set up the server so that all requests, including those from subdomains, go to index.php (the standard entry point, as in a regular yii project) where yii is launched.
Next are 2 options. The fact that Rules with Server Names is good if the controllers are different for each subdomain, etc., but in your case, as I understand it, you need to have, roughly speaking, school_id. Everything is identical, for all schools the same controllers and actions, but in some places the school_id, which apparently is a subdomain, is custom.
I have not tried this, but theoretically you can just make an alias, for example, in
common\config\bootstrap.php add something like:
only after checking what it returns $_SERVER['SERVER_NAME'], there can be a lot of surprises depending on the server settings
. Well, then use for example:

public function getPrepod(){
  return $this->hasOne(Prepod:classname, ['id'=>'prepod_id'])->andWhere(['school_id'=>Yii::getAlias('@school')]);
}

But again, I haven't tried it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question