space97
space97

Reputation: 303

How do I set domain based configuration in Symfony 3.4?

So I have set up a Symfony 3.4 application, which I downloaded following the instructions here using the Symfony Installer:

https://symfony.com/download

I am building this app for my employer to run within multiple eCommerce sites. It will not only have to have to use the prod, test, and dev configurations that come preinstalled in /app/config/ directory, but it will also need one set site unique configurations (mainly several twig globals, etc) for each site that it runs on.

My question is what is the best way to detect what site my app is running on and pass that into the configuration side of things?

I am looking at how dev, test, and prod work int web/app.php and web/app_dev.php and wondering if there is some way I can expand on that concept similarly based on the site domain.

Not sure if this matters but I am using the default Yaml configuration files that came with the framework download and would like to stick with that over the XML or PHP options.

Thanks for your help.

Upvotes: 1

Views: 917

Answers (1)

Chip Dean
Chip Dean

Reputation: 4302

You have several options to do this depending on your server configuration. What I did was define an environmental variable SYMFONY__ENV in my virtual host like this: SetEnv SYMFONY__ENV dev.

Then you can modify your web/app.php to read this variable.

$env = strtolower(getenv('SYMFONY__ENV'));
$kernel = new AppKernel($env, $env === 'dev' || $env === 'test');

As a commenter mentioned you should update to Symfony Flex when you can but you can use this configuration until you do.

Upvotes: 1

Related Questions