Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @Route("/todo/create", name="todo_create")
- */
- public function createAction(Request $request)
- {
- $todo= new Todo;
- $form =$this->createFormBuilder($todo)
- ->add('user',EntityType::class,array('class'=>'AppBundleEntityUser',
- 'choice_label'=>'username',
- 'expanded'=>false,
- 'multiple'=>false))
- ->add('nom',TextType::class,array('attr' => array('class'=>'form-control', 'style' =>'margin-bottom:15px')))
- ->add('prenom',TextType::class,array('attr' => array('class'=>'form-control', 'style' =>'margin-bottom:15px')))
- ->add('tel',TextType::class,array('attr' => array('class'=>'form-control', 'style' =>'margin-bottom:15px')))
- ->add('email',TextType::class,array('attr' => array('class'=>'form-control', 'style' =>'margin-bottom:15px')))
- ->add('Save',SubmitType::class, array('label' =>'Create', 'attr'=> array('class'=>'btn btn-primary', 'style' =>'margin-bottom:15px')))
- ->getForm();
- $form->handleRequest($request);
- if($form->isSubmitted() && $form->isValid()){
- $nom=$form['nom']->getData();
- $prenom=$form['prenom']->getData();
- $tel=$form['tel']->getData();
- $email=$form['email']->getData();
- $todo->setNom($nom);
- $todo->setPrenom($prenom);
- $todo->setTel($tel);
- $todo->setEmail($email);
- $repository = $this
- ->getDoctrine()
- ->getManager()
- ->getRepository('AppBundle:User');
- $user = $this->getUser();
- $em = $this->getDoctrine()->getManager();
- $todos = $em->getRepository('AppBundle:Todo')->findAll();
- foreach ($todos as $todo) {
- $user->addTodo($todo);
- }
- $em->flush();
- $this->addFlash(
- 'notice',
- 'Todo Added'
- );
- return $this -> redirectToRoute('todo_listeami');
- }
- return $this->render('todo/create.html.twig',
- array(
- 'form' => $form ->createView()
- ));
- }
- /**
- * @Route("/todo/listeami", name="todo_listeami")
- */
- public function listeamiAction(){
- $repository = $this
- ->getDoctrine()
- ->getManager()
- ->getRepository('AppBundle:User');
- $user = $this->getUser();
- $em = $this->getDoctrine()->getManager();
- $todos = $em->getRepository('AppBundle:Todo')->findAll();
- foreach ($todos as $todo) {
- $todos = $user->getTodos();
- }
- $em->flush();
- return $this->render('todo/listeami.html.twig',array(
- 'user'=>$user,
- ));
- }
- {% for todo in app.user.todos %}
- <tr>
- <th scope="row"></th>
- <td>{{todo.nom}}</td>
- <td>{{todo.prenom}}</td>
- <td>{{todo.email}}</td>
- <td>{{todo.tel}}</td>
- {% endfor %}
Add Comment
Please, Sign In to add comment