Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

environmental variables in host annotations

I am making an website which handles subdomains, i have setup an environmental variable called base_host and now i want to use this into the @route annotation in Symfony 4.

i have tried sofar: @Route("/", name="homepage", host="{afdeling}.{domain}", defaults={"domain"="%env(base_host)%"}, requirements={"domain"="%env(base_host)%"}) but this give me an error: using %env(base_host)% is not allowed in routing configuration

i have also tried: @Route("/", name="homepage", host="{afdeling}.%env(base_host)%") this did not work at all.

also what i have tried is: @Route("/", name="homepage", host="{afdeling}.{domain}", defaults={"domain"="%base_host%"}, requirements={"domain"="%base_host%"}) but this gives me the error message: The parameter "base_host" must be defined.

how can i achieve this?

like image 915
Giovanni Le Grand Avatar asked Nov 07 '17 18:11

Giovanni Le Grand


1 Answers

Environment variables are not supported (yet) inside routes configuration. As workaround you can create a "proxy" container parameter to achieve it:

# app/config/config.yml <= Sf 3.4 >= config/services.yaml
parameters:
    base_host: '%env(BASE_HOST)%'

Then use %base_host% for any route option.

like image 87
yceruto Avatar answered Oct 02 '22 00:10

yceruto