Load different app.php file according to domain

Hi, like many of us, I’m new to cakePHP and full of questions.

I want to develop a site which will load a different GUI and mainly uses a different database depending on the domain it was been requested.

My first thought was to play with $_SERVER predefined variable and alter the FileConfigTrait.php from
vendor\cakephp\cakephpsrc\Core\Configure\ folder.

if ($plugin) {
            $file = Plugin::configPath($plugin) . $key;
        } else {
			// Change: New lines to select different app.php 
                        // configuration file according to requested domain
			if($key == 'app') 
			// End Change
			$file = $this->_path . $key;

In that way if a create one app.php file for each domain - i.e. www.domain1.com_app.php for www.domain1.com - i can achieve my goal.

But i fill that this not right or at least there is a better way.

I guess You can have a base app.php and then in your bootstrap.php you can with a switch load more configuration based on the file, after the default configuration load

    $domain = parse_url($url, PHP_URL_HOST);

And you would have app.php, domain1.com.php, domain2.net.php in the config directory

1 Like

Thank you raul338

Yes that seems a better solution.