1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SumoCoders\FrameworkExampleBundle\Controller; |
4
|
|
|
|
5
|
|
|
use Knp\Menu\MenuItem; |
6
|
|
|
use SumoCoders\FrameworkExampleBundle\Form\Type\ButtonIconType; |
7
|
|
|
use SumoCoders\FrameworkExampleBundle\Form\Type\CollectionsType; |
8
|
|
|
use SumoCoders\FrameworkExampleBundle\Form\Type\DatePickerType; |
9
|
|
|
use SumoCoders\FrameworkExampleBundle\Form\Type\LabelsType; |
10
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
11
|
|
|
use Symfony\Component\HttpFoundation\Request; |
12
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
13
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
14
|
|
|
|
15
|
|
|
class TutorialController extends Controller |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @Route("/tutorial/datepicker") |
19
|
|
|
* @Template() |
20
|
|
|
* @return array |
21
|
|
|
*/ |
22
|
|
|
public function datePickerAction() |
23
|
|
|
{ |
24
|
|
|
$form = $this->createForm(DatePickerType::class); |
25
|
|
|
|
26
|
|
|
return array( |
27
|
|
|
'form' => $form->createView(), |
28
|
|
|
); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @Route("/tutorial/labels") |
33
|
|
|
* @Template() |
34
|
|
|
*/ |
35
|
|
|
public function labelsAction() |
36
|
|
|
{ |
37
|
|
|
$form = $this->createForm(LabelsType::class); |
38
|
|
|
|
39
|
|
|
return array( |
40
|
|
|
'form' => $form->createView(), |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @Route("/tutorial/button-icons") |
46
|
|
|
* @Template() |
47
|
|
|
*/ |
48
|
|
|
public function buttonIconsAction() |
49
|
|
|
{ |
50
|
|
|
$form = $this->createForm(ButtonIconType::class); |
51
|
|
|
|
52
|
|
|
return array( |
53
|
|
|
'form' => $form->createView(), |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @Route("/tutorial/statistics") |
59
|
|
|
* @Template() |
60
|
|
|
*/ |
61
|
|
|
public function statisticsAction() |
62
|
|
|
{ |
63
|
|
|
return array(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @Route("/tutorial/custom-bread-crumb") |
68
|
|
|
* @Template() |
69
|
|
|
*/ |
70
|
|
|
public function customBreadCrumbAction(Request $request) |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
/** @var /SumoCoders\FrameworkCoreBundle\BreadCrumb\BreadCrumbBuilder $breadCrumbBuilder */ |
|
|
|
|
73
|
|
|
$breadCrumbBuilder = $this->get('framework.breadcrumb_builder'); |
74
|
|
|
$factory = $this->get('knp_menu.factory'); |
75
|
|
|
|
76
|
|
|
$breadCrumbBuilder->dontExtractFromTheRequest(); |
77
|
|
|
$item = (new MenuItem('foo.bar', $factory)) |
78
|
|
|
->setlabel('First!') |
79
|
|
|
->setUri( |
80
|
|
|
$this->generateUrl('sumocoders_frameworkexample_tutorial_custombreadcrumb') . '#first' |
81
|
|
|
); |
82
|
|
|
|
83
|
|
|
$breadCrumbBuilder->addItem($item); |
84
|
|
|
$breadCrumbBuilder->addSimpleItem('Second'); |
85
|
|
|
$breadCrumbBuilder->addSimpleItem( |
86
|
|
|
'Third', |
87
|
|
|
$this->generateUrl('sumocoders_frameworkexample_tutorial_custombreadcrumb') . '#third' |
88
|
|
|
); |
89
|
|
|
|
90
|
|
|
return array(); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @Route("/tutorial/collections") |
95
|
|
|
* @Template() |
96
|
|
|
* @return array |
97
|
|
|
*/ |
98
|
|
|
public function collectionsAction() |
99
|
|
|
{ |
100
|
|
|
$form = $this->createForm(CollectionsType::class); |
101
|
|
|
|
102
|
|
|
return array( |
103
|
|
|
'form' => $form->createView(), |
104
|
|
|
); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @Route("/tutorial/send-mail") |
109
|
|
|
* @Template() |
110
|
|
|
* @param Request $request |
111
|
|
|
* @return array |
112
|
|
|
*/ |
113
|
|
|
public function sendMailAction(Request $request) |
114
|
|
|
{ |
115
|
|
|
$form = $this->createFormBuilder() |
116
|
|
|
->getForm(); |
117
|
|
|
|
118
|
|
|
$form->handleRequest($request); |
119
|
|
|
|
120
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
121
|
|
|
// get the message factory so we can create messages |
122
|
|
|
$messageFactory = $this->get('framework.message_factory'); |
123
|
|
|
|
124
|
|
|
// create a simple message |
125
|
|
|
$message = $messageFactory->createHtmlMessage( |
126
|
|
|
'the subject', |
127
|
|
|
'<p>foo bar</p>' |
128
|
|
|
); |
129
|
|
|
|
130
|
|
|
// set some extra properties, just like you would do with a normal \Swift_Message |
131
|
|
|
$message->setTo( |
132
|
|
|
$this->getParameter('mailer_default_to_email') |
133
|
|
|
); |
134
|
|
|
|
135
|
|
|
// send it |
136
|
|
|
$this->get('mailer')->send($message); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
return array( |
140
|
|
|
'form' => $form->createView(), |
141
|
|
|
); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.