سؤال

I need to embed one form into another form and I'm doing as follow:

use Symfony\Component\Form\AbstractType,
    Symfony\Component\Form\FormBuilderInterface,
    Symfony\Component\OptionsResolver\OptionsResolverInterface,
    Common\CommonBundle\Form\AddressExtraInfoType;

class StandardAddressType extends AbstractType {

    public function buildForm(FormBuilderInterface $builder, array $options) {
        $builder
                ->add('country', 'entity', array( ... ))
                ->add('state', 'entity', array( ... ))
                ->add('city', 'entity', array( ... ))
                ->add('extra_info', new AddressExtraInfoType());
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver) {
        $resolver->setDefaults(array(
            'data_class' => 'Common\CommonBundle\Entity\StandardAddress'
        ));
    }

    public function getName() {
        return 'common_commonbundle_standard_address';
    }

}

Since the main form need to be attached to the 'data_class' => 'Common\CommonBundle\Entity\StandardAddress' then when I try to get the form this error come up:

Neither the property "extra_info" nor one of the methods "getExtraInfo()", "isExtraInfo()", "hasExtraInfo()", "__get()" exist and have public access in class "Common\CommonBundle\Entity\StandardAddress"

How I can fix this? How I can embed the second form into the first one without get this eror?

هل كانت مفيدة؟

المحلول 2

Finally and after read my code once again I found where the error was. In my AddressExtraInfoentity I had address_extra_info and of course changing that to extra_info fix the issue, anyway thanks for your reply

نصائح أخرى

try this:

$builder->add('extra_info', new AddressExtraInfoType(), array('mapped' => false));

You don't have field extra_info in class Common\CommonBundle\Entity\StandardAddress so you must use non mapped field in form type

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top