I recently came across a problem that I solved. To solve this problem, I ended using setDefaultOptions insted of configureOptions in one of my form. The thing is that it got me asking, what's the difference between those two functions?
Here is the way they both look like in my form:
<?php
namespace AdminBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
//use Symfony\Component\OptionsResolver\OptionsResolver;
Class ProjetIntType extends AbstractType
{
public function buildForm(FormBuilderInterface $constructeur, array $options)
{
$constructeur
->add('langue', 'text')
->add('nom', 'text')
->add('descriptionCours', 'text')
->add('descriptionComplete', 'text')
->add('roles', 'text')
->add('aptitudesDeveloppees', 'text');
}
/*public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'PublicBundle\Entity\ProjetInt',
));
}*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'PublicBundle\Entity\ProjetInt',
));
}
public function getName()
{
return 'projetInt';
}
}
setDefaultOptions()
has been deprecated in favor of configureOptions()
. See UPGRADE-3.0.md. configureOptions()
was introduced in Symfony 2.7 and will be required in 3.0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With