Last active
January 29, 2022 23:53
-
-
Save ismail1432/c508e816e067d3493dcbcff0a9a4d819 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
// The form | |
namespace App\Form; | |
use App\Entity\Address; | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\Form\FormBuilderInterface; | |
use Symfony\Component\OptionsResolver\OptionsResolver; | |
class AddressType extends AbstractType | |
{ | |
public function buildForm(FormBuilderInterface $builder, array $options): void | |
{ | |
$builder | |
->add('country', EmojiType::class) | |
; | |
} | |
public function configureOptions(OptionsResolver $resolver): void | |
{ | |
$resolver->setDefaults([ | |
'data_class' => Address::class, | |
]); | |
} | |
} | |
namespace App\Controller; | |
use App\Form\AddressType; | |
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | |
use Symfony\Component\HttpFoundation\Response; | |
use Symfony\Component\Routing\Annotation\Route; | |
// The controller | |
class HelloController extends AbstractController | |
{ | |
#[Route('/hello', name: 'hello')] | |
public function index(): Response | |
{ | |
$form = $this->createForm(AddressType::class); | |
return $this->render('hello/index.html.twig', [ | |
'form' => $form->createView() | |
]); | |
} | |
} | |
// twig | |
<div class="example-wrapper"> | |
<h1>Address form </h1> | |
{{ form(form) }} | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment