Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.2k
Closed
Description
As ofsymfony/symfony#3239 the "collection" and "choice" types (with multiple=true) as well as subtypes (such as "entity") will try to discover an adder and a remover method in your modelif "by_reference" is set to false.
Example form:
$form = $this->createFormBuilder($article) ->add('tags', null, array('by_reference' => false)) ->getForm();
The underlying article class is expected to look like this:
class Article{ public function addTag($tag) { ... } public function removeTag($tag) { ... } public function getTags($tag) { ... }}
If adder and remover are not found, the form behaves differently depending on whethergetTags
returns an object or an array.
- If it returns an object (collection), the object is modified by reference and not written back
- If it returns an array, the array is modified and written back using
setTags
You can force a write-back in case (1) by setting the field option "by_reference" to false. Note that in this case, adders and removerswon't be used even if present! Instead, the expected object signature is
class Article{ public function setTags($tags) { ... } public function getTags($tag) { ... }}