Guest User

Untitled

a guest
Dec 13th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. /**
  2. * @Route("/todo/create", name="todo_create")
  3. */
  4.  
  5. public function createAction(Request $request)
  6. {
  7.  
  8. $todo= new Todo;
  9. $form =$this->createFormBuilder($todo)
  10. ->add('user',EntityType::class,array('class'=>'AppBundleEntityUser',
  11. 'choice_label'=>'username',
  12. 'expanded'=>false,
  13. 'multiple'=>false))
  14. ->add('nom',TextType::class,array('attr' => array('class'=>'form-control', 'style' =>'margin-bottom:15px')))
  15. ->add('prenom',TextType::class,array('attr' => array('class'=>'form-control', 'style' =>'margin-bottom:15px')))
  16. ->add('tel',TextType::class,array('attr' => array('class'=>'form-control', 'style' =>'margin-bottom:15px')))
  17. ->add('email',TextType::class,array('attr' => array('class'=>'form-control', 'style' =>'margin-bottom:15px')))
  18.  
  19. ->add('Save',SubmitType::class, array('label' =>'Create', 'attr'=> array('class'=>'btn btn-primary', 'style' =>'margin-bottom:15px')))
  20.  
  21. ->getForm();
  22. $form->handleRequest($request);
  23. if($form->isSubmitted() && $form->isValid()){
  24. $nom=$form['nom']->getData();
  25. $prenom=$form['prenom']->getData();
  26. $tel=$form['tel']->getData();
  27. $email=$form['email']->getData();
  28.  
  29. $todo->setNom($nom);
  30. $todo->setPrenom($prenom);
  31. $todo->setTel($tel);
  32. $todo->setEmail($email);
  33.  
  34. $repository = $this
  35. ->getDoctrine()
  36. ->getManager()
  37. ->getRepository('AppBundle:User');
  38. $user = $this->getUser();
  39.  
  40. $em = $this->getDoctrine()->getManager();
  41.  
  42. $todos = $em->getRepository('AppBundle:Todo')->findAll();
  43.  
  44. foreach ($todos as $todo) {
  45. $user->addTodo($todo);
  46. }
  47.  
  48. $em->flush();
  49.  
  50.  
  51. $this->addFlash(
  52. 'notice',
  53. 'Todo Added'
  54. );
  55.  
  56. return $this -> redirectToRoute('todo_listeami');
  57. }
  58. return $this->render('todo/create.html.twig',
  59. array(
  60.  
  61. 'form' => $form ->createView()
  62. ));
  63. }
  64.  
  65. /**
  66. * @Route("/todo/listeami", name="todo_listeami")
  67. */
  68.  
  69.  
  70. public function listeamiAction(){
  71. $repository = $this
  72. ->getDoctrine()
  73. ->getManager()
  74. ->getRepository('AppBundle:User');
  75.  
  76. $user = $this->getUser();
  77.  
  78.  
  79. $em = $this->getDoctrine()->getManager();
  80. $todos = $em->getRepository('AppBundle:Todo')->findAll();
  81.  
  82. foreach ($todos as $todo) {
  83. $todos = $user->getTodos();
  84. }
  85. $em->flush();
  86.  
  87.  
  88.  
  89.  
  90. return $this->render('todo/listeami.html.twig',array(
  91.  
  92. 'user'=>$user,
  93.  
  94.  
  95. ));
  96.  
  97. }
  98.  
  99. {% for todo in app.user.todos %}
  100. <tr>
  101. <th scope="row"></th>
  102. <td>{{todo.nom}}</td>
  103. <td>{{todo.prenom}}</td>
  104. <td>{{todo.email}}</td>
  105. <td>{{todo.tel}}</td>
  106. {% endfor %}
Add Comment
Please, Sign In to add comment