10000 Fix setValueTransformer() call by ajessu · Pull Request #64 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

Fix setValueTransformer() call #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions guides/doctrine/orm/form.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@ compatible field that handles arrays of values::
use Symfony\Component\Form\ChoiceField;
use Symfony\Bundle\DoctrineBundle\Form\ValueTransformer\CollectionToChoiceTransformer;

$productTransformer = new CollectionToChoiceTransformer(array(
'em' => $em,
'className' => 'Product',
));

$field = new ChoiceField('products', array(
'choices' => $productChoices,
'multiple' => true,
'expanded' => true,
'value_transformer' => $productTransformer,
));
$field->setValueTransformer(new CollectionToChoiceTransformer(array(
'em' => $em,
'className' => 'Product',
)));

// Important: Make sure to attach the value transformer before calling addField().
$form->addField($field);

The 'em' property expects the EntityManager, the 'className' property expects
Expand Down Expand Up @@ -70,12 +71,12 @@ be chosen from::
));
$engineerField = new ChoiceField('engineer', array(
'choices' => $userChoices,
'value_transformer' => $userTransformer,
));
$engineerField->setValueTransformer($userTransformer);
$reporterField = new ChoiceField('reporter', array(
'choices' => $userChoices,
'value_transformer' => $userTransformer,
));
$reporterField->setValueTransformer($userTransformer);

$form->add($engineerField);
$form->add($reporterField);
0