php - Symfony2 form entity field different beahviour -
i'm using symfony2 since few months. i'm able accomplish basic operations such crud, etc. i'm facing issue now, regarding two-entity form behaviour. i've got unique form there're 2 entities connected 2 different tables:
- guests
- email suggested guests
where every email_id foreign key guest row. every guest may have no emails, null foreign key particular row.
once form has been sent user, saved new record guest table i'd field email (belonging entity) saved different table , performing checks:
- if email present table should't saved need take id , save foreign key new guest row;
- if email isn't table, has saved , connected new guest;
- if guest doesn't fill email, null foreign key has put against guest , no record saved email table.
i found many articles entity-form crud operations few or nothing how customise insert/update @ 1 time according specific field in symfony2.
please can explains me how or if there's knows articles/examples for, please, can reports me articles?
this snippet of form:
class inyourmindtype extends abstracttype { public function buildform(formbuilderinterface $builder, array $options) { $builder->add('title', 'text', array( 'label' => 'label_think_title', 'required' => true, 'attr' => array( 'title' => 'label_think_title', 'class' => 'form-control' ) ))->add('thinkfriend', new inyourmindfriendtype
where new inyourmindfriendtypeis email. below controller's snippet instead. @ moment simple method saves form
function sendinyourmindaction(request $request) { $enform = new inyourmind; $form = $this->createform(new inyourmindtype, $enform); if ($request->getmethod() === 'post') { $form->bind($request); if ($form->isvalid()) { $em = $this->getdoctrine() ->getentitymanager(); $em->merge($enform); $em->flush(); $this->get('session') ->getflashbag() ->set('think-success-notice', 'message sent'); return $this->redirect($this->generateurl('commonmainbundle_homepage')); } } return 'something'; }
Comments
Post a Comment