I'm reading the Symfony 2 tutorials. The early tutorials make it clear
to me that:

* Bundles are great
* The ability to call actions from other actions is a big improvement
on actions + components + partials + ...
* Twig fills the remaining roles of the old Symfony view/controller
concepts by providing blocks (which act like Symfony 1.x slots) and as
many layers of 'layouts' as you want (the 'extends' mechanism)

No questions here, just a lot of applause.

Now I'm reading about Doctrine and forms. This part is a little puzzling.

I get that:

* Annotations are a cool way to define columns
* You can generate entity classes or just write them
* Doctrine 2 is much faster
* The "do a bunch of stuff then call flush()" pattern is a big part of
the reason why and very efficient

But this tutorial on Doctrine and forms is less clear:

http://docs.symfony-reloaded.org/guides/doctrine/orm/form.html

The tutorial says that EntityToIDTransformer makes it easier to move
back and forth between an entity and an ID, and that this allows you
to select many-to-one or one-to-one entities in choice fields. But it
never actually demonstrates that. The code gets the ids and names
manually:

$userChoices = array();
$users = $em->getRepository('User')->findAll();
foreach ($users AS $user) {
    $userChoices[$user->id] = $user->name;
}

Then it sets up a field in a form:

$userTransformer = new EntityToIDTransformer(array(
    'em' => $em,
    'className' => 'User',
));
$engineerField = new ChoiceField('engineer', array(
    'choices' => $userChoices,
));
$engineerField->setValueTransformer($userTransformer);

$form->add($engineerField);

... And that's all it shows.

My question: what does this transformer actually do for me? It seems
to me that I could write this exact code, minus the transformer part,
and it would still work.

I suspect the answer is that later I'll be able to get the engineer
value from the form and discover I've received an object, not just an
ID, but this is never mentioned or demonstrated.

-- 
Tom Boutell
P'unk Avenue
215 755 1330
punkave.com
window.punkave.com

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to