aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Acme/DemoBundle/Controller/DemoController.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Acme/DemoBundle/Controller/DemoController.php')
-rw-r--r--src/Acme/DemoBundle/Controller/DemoController.php56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/Acme/DemoBundle/Controller/DemoController.php b/src/Acme/DemoBundle/Controller/DemoController.php
new file mode 100644
index 00000000..a99de891
--- /dev/null
+++ b/src/Acme/DemoBundle/Controller/DemoController.php
@@ -0,0 +1,56 @@
1<?php
2
3namespace Acme\DemoBundle\Controller;
4
5use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6use Symfony\Component\HttpFoundation\RedirectResponse;
7use Symfony\Component\HttpFoundation\Request;
8use Acme\DemoBundle\Form\ContactType;
9
10// these import the "@Route" and "@Template" annotations
11use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
12use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
13
14class DemoController extends Controller
15{
16 /**
17 * @Route("/", name="_demo")
18 * @Template()
19 */
20 public function indexAction()
21 {
22 return array();
23 }
24
25 /**
26 * @Route("/hello/{name}", name="_demo_hello")
27 * @Template()
28 */
29 public function helloAction($name)
30 {
31 return array('name' => $name);
32 }
33
34 /**
35 * @Route("/contact", name="_demo_contact")
36 * @Template()
37 */
38 public function contactAction(Request $request)
39 {
40 $form = $this->createForm(new ContactType());
41 $form->handleRequest($request);
42
43 if ($form->isValid()) {
44 $mailer = $this->get('mailer');
45
46 // .. setup a message and send it
47 // http://symfony.com/doc/current/cookbook/email.html
48
49 $request->getSession()->getFlashBag()->set('notice', 'Message sent!');
50
51 return new RedirectResponse($this->generateUrl('_demo'));
52 }
53
54 return array('form' => $form->createView());
55 }
56}