Skip to content

Instantly share code, notes, and snippets.

@tatma
Last active December 7, 2018 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tatma/832a7f46c95528752a2de7c3e09b93c3 to your computer and use it in GitHub Desktop.
Save tatma/832a7f46c95528752a2de7c3e09b93c3 to your computer and use it in GitHub Desktop.
Form Type con configureOptions
<?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