ArrayNodeDefinition::useAttributeAsKey()

ArrayNodeDefinition useAttributeAsKey(string $name, bool $removeKeyItem = true)

Sets the attribute which value is to be used as key.

This is useful when you have an indexed array that should be an associative array. You can select an item from within the array to be the key of the particular item. For example, if "id" is the "key", then:

array(
    array('id' => 'my_name', 'foo' => 'bar'),
);

becomes

array(
    'my_name' => array('foo' => 'bar'),
);

If you'd like "'id' => 'my_name'" to still be present in the resulting array, then you can set the second argument of this method to false.

This method is applicable to prototype nodes only.

Parameters

string $name The name of the key
bool $removeKeyItem Whether or not the key item should be removed

Return Value

ArrayNodeDefinition
doc_Symfony
2016-10-28 06:06:04
Comments
Leave a Comment

Please login to continue.