]>
Commit | Line | Data |
---|---|---|
93fd4692 NL |
1 | <?php |
2 | ||
3 | namespace Acme\DemoBundle\Controller; | |
4 | ||
5 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |
6 | use Symfony\Component\HttpFoundation\RedirectResponse; | |
7 | use Symfony\Component\HttpFoundation\Request; | |
8 | use Acme\DemoBundle\Form\ContactType; | |
9 | ||
10 | // these import the "@Route" and "@Template" annotations | |
11 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | |
12 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; | |
13 | ||
14 | class 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 | } |