Advertisement
Guest User

Todo List

a guest
Mar 29th, 2017
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. <?php
  2.  
  3. namespace AppBundle\Controller;
  4.  
  5. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  6. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use AppBundle\Entity\Todo;
  9. use Symfony\Component\Form\Extension\Core\Type\TextType;
  10. use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
  11. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  12. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  13.  
  14. class ToDoController extends Controller
  15. {
  16. /**
  17. * @Route("/todo", name="todo_list")
  18. * @param Request $request
  19. * @return \Symfony\Component\HttpFoundation\Response
  20. */
  21. public function listAction()
  22. {
  23. $todos = $this->getDoctrine()->getRepository('AppBundle:Todo')->findAll();
  24. return $this->render('todo/index.html.twig', array(
  25. 'todos' => $todos
  26. ));
  27. }
  28.  
  29. /**
  30. * @Route("/todo/create", name="todo_create")
  31. * @param Request $request
  32. * @return \Symfony\Component\HttpFoundation\Response
  33. */
  34. public function createAction(Request $request)
  35. {
  36. $todo = new Todo();
  37.  
  38. $form = $this->createFormBuilder($todo)
  39. ->add('name', TextType::class, array('attr' => array('class' => 'form-control', 'style' => 'margin-bottom:15px')))
  40. ->add('category', TextType::class, array('attr' => array('class' => 'form-control', 'style' => 'margin-bottom:15px')))
  41. ->add('description', TextareaType::class, array('attr' => array('class' => 'form-control', 'style' => 'margin-bottom:15px')))
  42. ->add('due_date', DateTimeType::class, array('choices' => array('Low' => 'Low', 'Normal' => 'Normal', 'High' => 'High'), 'attr' => array('class' => 'form-control', 'style' => 'margin-bottom:15px')))
  43. ->getForm();
  44.  
  45. $form->handleRequest($request);
  46.  
  47. if ($form->isSubmitted() && $form->isValid()) {
  48. die('Submitted');
  49. }
  50.  
  51. return $this->render('todo/create.html.twig', array(
  52. 'form' => $form->createView()
  53. ));
  54. }
  55.  
  56. /**
  57. * @Route("todo/edit/{id}", name="todo_edit")
  58. * @param $id
  59. * @param Request $request
  60. * @return \Symfony\Component\HttpFoundation\Response
  61. */
  62. public function editAction($id, Request $request)
  63. {
  64. return $this->render('todo/edit.html.twig');
  65. }
  66.  
  67. /**
  68. * @Route("/todo/details/{id}", name="todo_details")
  69. */
  70. public function detailsAction($id)
  71. {
  72. return $this->render('todo/details.html.twig');
  73. }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement