Initial commit with Symfony 2.1+Vendors
Signed-off-by: Gergely POLONKAI (W00d5t0ck) <polesz@w00d5t0ck.info>
This commit is contained in:
57
src/Acme/DemoBundle/Controller/DemoController.php
Normal file
57
src/Acme/DemoBundle/Controller/DemoController.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?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 ('POST' == $request->getMethod()) {
|
||||
$form->bindRequest($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')->setFlash('notice', 'Message sent!');
|
||||
|
||||
return new RedirectResponse($this->generateUrl('_demo'));
|
||||
}
|
||||
}
|
||||
|
||||
return array('form' => $form->createView());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user