Development

Changeset 1395

You must first sign up to be able to contribute.

Changeset 1395

Show
Ignore:
Timestamp:
06/06/06 12:27:23 (2 years ago)
Author:
francois
Message:

documented scriptable configuration (ability to put PHP code in YAML files)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/doc/book/content/configuration.txt

    r1375 r1395  
    5858        # Use blanks instead 
    5959        all: 
    60         ��mail: 
    61         ����webmaster: webmaster@mysite.com 
     60          mail: 
     61            webmaster: webmaster@mysite.com 
    6262 
    6363* To define an array as a value, enclose the elements in square brackets or use the expanded syntax with dashes: 
     
    248248But maybe you need to add an array, an associative array or a lot of new parameters. In this case it is better to create a new configuration file, together with the corresponding configuration handler. 
    249249 
     250Scriptable configuration 
     251------------------------ 
     252 
     253It may happen that your configuration relies on external parameters (such as a database, or another configuration file). For these particular cases, the symfony configuration files are parsed as a PHP file before being passed to the YAML parser. It means that you can write: 
     254 
     255    [php] 
     256    all: 
     257      translation: 
     258        format:  <?php echo sfConfig::get('sf_i18n') == true ? 'xliff' : 'none' ?> 
     259 
     260That's right: *you can put PHP code in YAML files*! 
     261 
     262Beware though that the configuration is parsed very early in the life of a request, so you will have no symfony built-in methods or functions to help you. If you want one configuration file to rely on another, you have to make sure that the file you rely on is parsed before (look in the [symfony source](http://www.symfony-project.com/trac/browser/trunk/lib/symfony.php) to find in which order the configuration files are parsed). The `app.yml` is one of the last files parsed, so you may rely on others in it.  
     263 
     264Be also aware that in the production environment, the configuration is cached, so the configuration files are parsed (and executed) only once after the cache is cleared. 
     265 
    250266Configuration handlers 
    251267----------------------