Last active
December 7, 2018 18:23
-
-
Save tatma/832a7f46c95528752a2de7c3e09b93c3 to your computer and use it in GitHub Desktop.
Form Type con configureOptions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Form; | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\Form\FormBuilderInterface; | |
use Symfony\Component\Form\Extension\Core\Type\TextType; | |
use Symfony\Component\Form\Extension\Core\Type\TextareaType; | |
use Symfony\Component\OptionsResolver\OptionsResolver; | |
class ArticleType extends AbstractType | |
{ | |
public function buildForm(FormBuilderInterface $builder, array $options) | |
{ | |
$builder | |
->add('title', TextType::class, ['required' => true]) | |
->add('content', TextareaType::class, ['required' => true]) | |
->getForm(); | |
} | |
public function configureOptions(OptionsResolver $resolver) | |
{ | |
$resolver->setDefaults([ | |
'data_class' => App\Entity\Article::class | |
]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment