Skip to content

Instantly share code, notes, and snippets.

@mhlavac
Created May 24, 2016 12:23
Show Gist options
  • Save mhlavac/0c2ba5ca5c7e95e5e7d83d7c36164405 to your computer and use it in GitHub Desktop.
Save mhlavac/0c2ba5ca5c7e95e5e7d83d7c36164405 to your computer and use it in GitHub Desktop.
Symfony2 inherit_data issues and workaround
<?php
class NameType extends \Symfony\Component\Form\AbstractType
{
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder, array $options)
{
$builder->add('firstName', 'text');
$builder->add('lastName', 'text');
}
}
<?php
class Person
{
public $firstName;
public $lastName;
public $age;
}
<?php
class PersonType extends \Symfony\Component\Form\AbstractType
{
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder, array $options)
{
$builder->add('name', NameType::class, ['inherit_data' => true]);
$builder->add('age', 'integer');
}
}
<?php
class User
{
public $firstName;
public $lastName;
public $email;
}
<?php
class PersonType extends \Symfony\Component\Form\AbstractType
{
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder, array $options)
{
$builder->add('name', NameType::class, ['inherit_data' => true]);
$builder->add('email', 'email');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment