symfony2 - Assigning value to data_class in form type -
i have form type , wish know set against data_class in setdefaultoptions in case below. know set path of our entity in case have 2 entities embedded do now?
i know can leave ignore don't want it's suggested not sensiolabs (...so, while not necessary, it's thought explicitly specify data_class option...).
$resolver->setdefaults(array('data_class' => '?????????????????????')); form type:
namespace car\brandbundle\form\type; utilize symfony\component\form\abstracttype; utilize symfony\component\form\formbuilderinterface; utilize symfony\component\optionsresolver\optionsresolverinterface; class bothtype extends abstracttype { public function buildform(formbuilderinterface $builder, array $options) { $builder ->setmethod('post') ->setaction($options['action']) ->add('brands', new brandstype()) ->add('cars', new carstype()) ->add('button', 'submit', array('label' => 'add')) ; } public function setdefaultoptions(optionsresolverinterface $resolver) { $resolver->setdefaults(array('data_class' => '?????????????????????')); } public function getname() { homecoming 'both'; } } controller:
namespace car\brandbundle\controller; utilize car\brandbundle\entity\brands; utilize car\brandbundle\entity\cars; utilize car\brandbundle\form\type\bothtype; utilize symfony\bundle\frameworkbundle\controller\controller; class bothcontroller extends controller { public function indexaction() { $entity = array(new brands(), new cars()); $form = $this->createform(new bothtype(), $entity, array('action' => $this->generateurl('bothcreate'))); homecoming $this->render('carbrandbundle:default:both.html.twig', array('page' => 'both', 'form' => $form->createview())); } } when echo submitted info i'm getting replicated data:
array ( [0] => car\brandbundle\entity\brands object ( [id:protected] => [name:protected] => [origin:protected] => ) [1] => car\brandbundle\entity\cars object ( [id:protected] => [model:protected] => [price:protected] => ) [brands] => car\brandbundle\entity\brands object ( [id:protected] => [name:protected] => mercedes [origin:protected] => federal republic of germany ) [cars] => car\brandbundle\entity\cars object ( [id:protected] => [model:protected] => sl500 [price:protected] => 25,000 ) )
i think best way here ignore there no specific entity link to. doc should read "if form bound entity improve to".
symfony2
No comments:
Post a Comment