doulao2128 2016-04-09 15:00
浏览 57
已采纳

更改Symfony2项目的默认配置文件

Context

I have a simple Symfony2 project (only command line commands). This project includes an app/config.yml file, containing information used for dependency injection creation.

For example, app/config.yml contains:

github:
    token: abcdefgh

And src/Foo/Resources/config/github.yml (services files) contains:

services:
    github.client:
        class: Github\Client
        calls:
            - ['authenticate', [%github.token%, null, 'http_token']]

The file app/config.yml is loaded by Application::__construct() function.

When I run app/console mycommand, it uses the defined token.

Needs

I need to be able to run my commands using different configurations. For now, I replace manually the app/config.yml file, but it's crappy.

To do this, I thought about 2 possible solutions:

  • Be able to specify another app/config.yml file when I run app/console mycommand --f=app/config2.yml.
  • Have another configuration file for specific command usage, and use it with app/console mycommand --f=myconfig.yml. The thing is the dependency injection can not work or be updated after the application is run.

I don't know how to do one of this solution (or a third one, no matters). If it's a common behavior, can you point me some documentation or example to do something like this?

  • 写回答

1条回答 默认 最新

  • dongyou1926 2016-04-09 15:19
    关注

    It is totally possible by using different environements, check out the doc : http://symfony.com/doc/current/cookbook/configuration/environments.html

    Typically you will specify the environement using --env=myenv.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有没有可以帮我搞一个微信建群链接,包括群名称和群资料群头像那种,不会让你白忙
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题