php - How to validate entity with associaction?
Get the solution ↓↓↓Solution:
You'll want to make a form for your Address Entity, something like:
use AppBundle\Entity\Address;
// ...
class AddressType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('address1', TextType::class);
$builder->add('city', TextType::class);
// ...
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Address::class,
]);
}
}
Then update yourCustomerType
to use that class, something like:
use AppBundle\Form\Type\AddressType;
// ...
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name', TextType::class);
$builder->add('surname', TextType::class);
$builder->add('address', AddressType::class);
}
Then your Address entity should be validated automatically without needing a custom validation constraint.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: please make sure the php redis extension is installed and enabled.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.