简体   繁体   English

Symfony2仅在生产中启用HOST路由参数

[英]Symfony2 enable HOST route parameter in production only

is it possible to enable the HOST parameter in symfony2 routing for production only? 是否可以仅在生产中启用symfony2路由中的HOST参数? Or possibly have a dynamic value that i can import from parameters.yml? 或者可能有一个我可以从parameters.yml导入的动态值?

Cant seen to find documentation on this. 不能找到有关此文档。

First, create a specific routing file for each environment, like routing_dev.yml and routing_prod.yml . 首先,为每个环境创建一个特定的路由文件,例如routing_dev.ymlrouting_prod.yml

In your config.yml, load the routing corresponding to your env by doing : 在您的config.yml中,通过执行以下操作来加载与您的环境相对应的路由:

# app/config/config.yml
#....
framework:
    router:
         resource: "%kernel.root_dir%/config/routing_%kernel_environment%.yml"

Now, add your custom host based routes in the routing_prod.yml. 现在,在routing_prod.yml中添加基于自定义主机的路由。 Example : 范例:

# app/config/routing_prod.yml
acme_home:
    host: "%domain%"
    path: /
    defaults: { _controller: AcmeAppBundle:Default:home }

 acme_api:
     host: "api.%domain%"
     path: /
     defaults: { _controller: AcmeAppBundle:Default:api }

And

# app/config/parameters.yml
domain: home.example.com

Hope this is what you need. 希望这是您所需要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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