123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace Acme\DemoBundle\Controller;
- use Symfony\Bundle\FrameworkBundle\Controller\Controller;
- use Symfony\Component\HttpFoundation\RedirectResponse;
- use Acme\DemoBundle\Form\ContactType;
- // these import the "@Route" and "@Template" annotations
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
- class DemoController extends Controller
- {
- /**
- * @Route("/", name="_demo")
- * @Template()
- */
- public function indexAction()
- {
- return array();
- }
- /**
- * @Route("/hello/{name}", name="_demo_hello")
- * @Template()
- */
- public function helloAction($name)
- {
- return array('name' => $name);
- }
- /**
- * @Route("/contact", name="_demo_contact")
- * @Template()
- */
- public function contactAction()
- {
- $form = $this->get('form.factory')->create(new ContactType());
- $request = $this->get('request');
- if ($request->isMethod('POST')) {
- $form->bind($request);
- if ($form->isValid()) {
- $mailer = $this->get('mailer');
- // .. setup a message and send it
- // http://symfony.com/doc/current/cookbook/email.html
- $this->get('session')->getFlashBag()->set('notice', 'Message sent!');
- return new RedirectResponse($this->generateUrl('_demo'));
- }
- }
- return array('form' => $form->createView());
- }
- }
|