简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM