src/Controller/TimeController.php line 15

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Component\Validator\Constraints\NotBlank;
  9. class TimeController extends AbstractController
  10. {
  11.     #[Route('/time'name'app_time')]
  12.     public function index(Request $request): Response
  13.     {
  14.         $defaults = [
  15.             'targetHr' => 40,
  16.             'targetMin' => 0,
  17.         ];
  18.         $form $this
  19.             ->createFormBuilder($defaults)
  20.             ->add('currentHr'NumberType::class, [
  21.                 'constraints' => new NotBlank(),
  22.                 'label' => 'Std.',
  23.                 'row_attr' => [
  24.                     'class' => 'input-group',
  25.                 ],
  26.             ])
  27.             ->add('currentMin'NumberType::class, [
  28.                 'constraints' => new NotBlank(),
  29.                 'label' => 'Min.',
  30.                 'row_attr' => [
  31.                     'class' => 'input-group',
  32.                 ],
  33.             ])
  34.             ->add('targetHr'NumberType::class, [
  35.                 'constraints' => new NotBlank(),
  36.                 'label' => 'Std.',
  37.                 'row_attr' => [
  38.                     'class' => 'input-group',
  39.                 ],
  40.             ])
  41.             ->add('targetMin'NumberType::class, [
  42.                 'constraints' => new NotBlank(),
  43.                 'label' => 'Min.',
  44.                 'row_attr' => [
  45.                     'class' => 'input-group',
  46.                 ],
  47.             ])
  48.             ->getForm();
  49.         $form->handleRequest($request);
  50.         if ($form->isSubmitted() && $form->isValid()) {
  51.             $data $form->getData();
  52.             dd($data);
  53.         }
  54.         return $this->render('time/index.html.twig', [
  55.             'controller_name' => 'TimeController',
  56.             'form' => $form->createView(),
  57.         ]);
  58.     }
  59. }