How to create a custom yaml config file in Symfony

前端 未结 6 550
面向向阳花
面向向阳花 2021-02-02 13:52

What I want to do is quite simple: store data in a custom config file that I want to read later on.

I created my file something.yml that I put in the global

6条回答
  •  自闭症患者
    2021-02-02 13:55

    It's really easy, but also a little bit hacky:

    Create the file /config/config_handlers.yml and add this:

    config/something.yml:
      class:    sfDefineEnvironmentConfigHandler
      param:
        prefix: something_
    

    Then add these two lines to /web/index.php after ... getApplicationConfiguration() (and also add them to frontend_dev.php and wherever you want this config file to be available):

    $configCache = new sfConfigCache($configuration);
    include($configCache->checkConfig('config/something.yml'));
    

    So your /web/index.php might look like this afterwards:

    checkConfig('config/something.yml');
    sfContext::createInstance($configuration)->dispatch();
    

    Btw: This is also in the documentation you cited, although the checkConfig() call is in a different place. Look for this: "When you need the code based on the map.yml file and generated by the myMapConfigHandler handler in your application, call the following line:"

    Have fun ;-)

提交回复
热议问题