Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace AppBundle\Controller;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
- use Symfony\Bundle\FrameworkBundle\Controller\Controller;
- use Symfony\Component\HttpFoundation\Request;
- use AppBundle\Entity\Todo;
- use Symfony\Component\Form\Extension\Core\Type\TextType;
- use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
- use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
- use Symfony\Component\Form\Extension\Core\Type\TextareaType;
- class ToDoController extends Controller
- {
- /**
- * @Route("/todo", name="todo_list")
- * @param Request $request
- * @return \Symfony\Component\HttpFoundation\Response
- */
- public function listAction()
- {
- $todos = $this->getDoctrine()->getRepository('AppBundle:Todo')->findAll();
- return $this->render('todo/index.html.twig', array(
- 'todos' => $todos
- ));
- }
- /**
- * @Route("/todo/create", name="todo_create")
- * @param Request $request
- * @return \Symfony\Component\HttpFoundation\Response
- */
- public function createAction(Request $request)
- {
- $todo = new Todo();
- $form = $this->createFormBuilder($todo)
- ->add('name', TextType::class, array('attr' => array('class' => 'form-control', 'style' => 'margin-bottom:15px')))
- ->add('category', TextType::class, array('attr' => array('class' => 'form-control', 'style' => 'margin-bottom:15px')))
- ->add('description', TextareaType::class, array('attr' => array('class' => 'form-control', 'style' => 'margin-bottom:15px')))
- ->add('due_date', DateTimeType::class, array('choices' => array('Low' => 'Low', 'Normal' => 'Normal', 'High' => 'High'), 'attr' => array('class' => 'form-control', 'style' => 'margin-bottom:15px')))
- ->getForm();
- $form->handleRequest($request);
- if ($form->isSubmitted() && $form->isValid()) {
- die('Submitted');
- }
- return $this->render('todo/create.html.twig', array(
- 'form' => $form->createView()
- ));
- }
- /**
- * @Route("todo/edit/{id}", name="todo_edit")
- * @param $id
- * @param Request $request
- * @return \Symfony\Component\HttpFoundation\Response
- */
- public function editAction($id, Request $request)
- {
- return $this->render('todo/edit.html.twig');
- }
- /**
- * @Route("/todo/details/{id}", name="todo_details")
- */
- public function detailsAction($id)
- {
- return $this->render('todo/details.html.twig');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement