I'm building a website that has a "subdomain" called marketplace. so the url will be marketplace.sample.com. I'm using the Yii2 advanced application and I added the following code to my index.php located in frontend/web.
defined('MARKETPLACE') or define('MARKETPLACE', preg_match('/^marketplace/', $_SERVER['HTTP_HOST']) === 1 ? true : false);
This works on my environment, however, I just realized that the index.php file is in the .gitignore file in Yii2 because that file is created by the init script and so changes to it will be overwritten by running the init.
Anyway, so the question is: Where do I put this code so that it can be committed and shared with the rest of the dev team and make it to production when the code is pushed?
I tried to put this code in the common/config/params.php but then when I try to access the variable to determine which route to use I can't because the Yii app has not be initialized when the frontend/config/main.php file is run and I get an error that I am trying to access a property of a non-object.
/frontend/config/main.php
'defaultRoute' => MARKETPLACE ? 'marketplace' : 'site',
/frontend/config/main.php (with param instead)
'defaultRoute' => Yii::$app->params['marketplace'] ? 'marketplace' : 'site'
this second one gives the error that I am trying to access a property of a non-object.