Answer the question
In order to leave comments, you need to log in
Symfony3 How to write to two tables in one controller?
Goodnight.
The situation is as follows, there is a FOSUserBundle registration, there are 2 tables users and info_user.
How it is possible to write down the data at once in two tables of the form for users:
- username;
- password;
- email;
info_user form:
- lastname;
- firstname;
- phone;
Thanks for the help, using symfony3.3.5
Answer the question
In order to leave comments, you need to log in
public function createAction(Request $request)
{
$individualUser = new IndividualUser();
$iform = $this->createForm('BackendBundle\Form\IndividualUserType', $individualUser);
$iform->handleRequest($request);
$user = new User();
$form = $this->createForm('BackendBundle\Form\UserType', $user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$individualUser->setUser($user->getId());
$em->persist($individualUser);
$em->persist($user);
$em->flush();
return $this->redirectToRoute('_user_index');
}
return $this->render('BackendBundle:User:create.html.twig',array(
'form' => $form->createView(),
'iform' => $oform->createView()
));
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question