1
|
|
|
<?php |
2
|
|
|
namespace AppBundle\Controller; |
3
|
|
|
|
4
|
|
|
use AppBundle\Entity\Task; |
5
|
|
|
use AppBundle\Form\TaskType; |
6
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
7
|
|
|
use Symfony\Component\Form\Extension\Core\Type\DateType; |
8
|
|
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType; |
9
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
10
|
|
|
use Symfony\Component\HttpFoundation\Request; |
11
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @Route("/form") |
15
|
|
|
*/ |
16
|
|
|
class FormController extends Controller |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @Route("/simple", name="form_simple") |
20
|
|
|
*/ |
21
|
|
|
public function simpleAction(Request $request) |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
$task = new Task(); |
24
|
|
|
$task->setTitle('Make it work!'); |
25
|
|
|
$task->setDateCreated(new \DateTime()); |
26
|
|
|
|
27
|
|
|
$form = $this->createFormBuilder($task) |
28
|
|
|
->add('title', TextType::class) |
29
|
|
|
->add('dateCreated', DateType::class) |
30
|
|
|
->add('save', SubmitType::class, array('label' => 'Create Task')) |
31
|
|
|
->getForm(); |
32
|
|
|
|
33
|
|
|
return $this->render( |
34
|
|
|
'form/new.html.twig', array( |
35
|
|
|
'form' => $form->createView(), |
36
|
|
|
) |
37
|
|
|
); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @Route("/class", name="form_class") |
42
|
|
|
*/ |
43
|
|
|
public function classAction(Request $request) |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
$task = new Task(); |
46
|
|
|
$task->setTitle('Make it work!'); |
47
|
|
|
|
48
|
|
|
$form = $this->createForm(TaskType::class, $task); |
49
|
|
|
|
50
|
|
|
return $this->render( |
51
|
|
|
'form/new.html.twig', array( |
52
|
|
|
'form' => $form->createView(), |
53
|
|
|
) |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.