简体   繁体   中英

Difference between configureOptions and setDefaultOptions ina form in Symfony 2

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM