Sometimes its useful to return an array of values from app.yml. This is buried in the symfony docs so I thought I’d post it here just in case it’d help.
I’ve been using this technique to store a list of languages available on a site. As translations are ready for other languages, I add them to the list here and they automatically get pulled into the code in the appropriate places:
.array:
languages:
en_US: English
he_IL: HebrewThis allows you to retrieve the value of your “languages” parameter as an array:
$languages = sfConfig::get('app_languages'); print_r($languages); /* output: Array ( [en_US] => English [he_IL] => Hebrew ) */
If you didn’t use the “.array” syntax, you would have to retrieve each language like this:
// in app.yml languages: en_US: English he_IL: Hebrew
$languages = sfConfig::get('app_languages'); // returns NULL $english = sfConfig::get('app_languages_en_US'); // returns English
You can read more about this in the symfony book. Can anyone verify this works in the latest version of symfony?




Yes, it’s valid syntax so will be supported indefinitely as there would be no reason to remove it. The “dot notation” defines a header, and anything below that is treated as an array.
It does not need to be .array, but can be .anything, however this is purely for the yaml file, as whatever word you use is ignored when the yaml file is parsed into a php array.
By Russ on Jul 13, 2009
actually in the app.yml the “dotnotation” is not just a header as described in the docs and used in other areas e.g settings.yml, I just tested it now.
It wouldnt print an array unless i included the .header
…is this a bug in the sfconfig::get function??
By chris on Jul 13, 2009
My friend Lawrence discusses this a bit more in depth on his blog. http://www.teamlalala.com/blog/2009/09/20/how-to-get-an-array-out-of-a-yaml-file-using-symfonys-parser/
By Scott Meves on Sep 24, 2009
Yes, it’s valid sintax in symfony 1.3/1.4
By Rodrigo on Dec 11, 2009
I just noticed app.yml can only have one .array declaration (to confirm):
.array
var:
foo: bar
fooa: bara
var2:
foo2: bar2
By sglessard on Feb 24, 2010