This is in response to the use of DI on Abstract Classes. The discussion originated here but I think it is a matter of importance so i am turning this into a blog post.
hi Bernhard, I don’t think he has listened you yet, judging for his latest post on collection forms he still passes does it twice:
Here:
$form = $this->createForm(new \Khepin\GolfBundle\Form\ParSetType($course)); // should be $form = $this->createForm(new \Khepin\GolfBundle\Form\ParSetType(), $course); |
And here:
$builder->get('holes')->add('hole_'.$i, new HoleType($hole)); // should be $builder->get('holes')->add('hole_'.$i, new HoleType(), $hole); // <--- Is this possible!!! I wonder about the add signature!! |
So I found out there is a space for a data option here:
So the code should now look like:
$builder->get('holes')->add('hole_'.$i, new HoleType(), array( 'data' => $hole ) ); |
I have not tried if this works but at least it has some support.
@Bernhard can you please help me out with the last part? how it should be done?
thanks! I will update this blog post as this is resolved.
Hi Luis,
First of all, this Don’t does not concern abstract classes in Symfony2 (in general), but form type classes. You can hopefully find an answer to your question in my comment to the previous blog post: http://sf.khepin.com/2011/08/form-composition-in-symfony2/#comment-1146
Bernhard
thanks Bernhard, i think it was helpful. I resolved my issue another way, it is related but not really this. Thanks anyway. Whatever helps us understand the form component better works.