forked from wallabag/wallabag
symfony is there
This commit is contained in:
56
src/Acme/DemoBundle/Controller/DemoController.php
Normal file
56
src/Acme/DemoBundle/Controller/DemoController.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Acme\DemoBundle\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
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(Request $request)
|
||||
{
|
||||
$form = $this->createForm(new ContactType());
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
$mailer = $this->get('mailer');
|
||||
|
||||
// .. setup a message and send it
|
||||
// http://symfony.com/doc/current/cookbook/email.html
|
||||
|
||||
$request->getSession()->getFlashBag()->set('notice', 'Message sent!');
|
||||
|
||||
return new RedirectResponse($this->generateUrl('_demo'));
|
||||
}
|
||||
|
||||
return array('form' => $form->createView());
|
||||
}
|
||||
}
|
||||
70
src/Acme/DemoBundle/Controller/SecuredController.php
Normal file
70
src/Acme/DemoBundle/Controller/SecuredController.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace Acme\DemoBundle\Controller;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Security\Core\SecurityContext;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
|
||||
/**
|
||||
* @Route("/demo/secured")
|
||||
*/
|
||||
class SecuredController extends Controller
|
||||
{
|
||||
/**
|
||||
* @Route("/login", name="_demo_login")
|
||||
* @Template()
|
||||
*/
|
||||
public function loginAction(Request $request)
|
||||
{
|
||||
if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
|
||||
$error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
|
||||
} else {
|
||||
$error = $request->getSession()->get(SecurityContext::AUTHENTICATION_ERROR);
|
||||
}
|
||||
|
||||
return array(
|
||||
'last_username' => $request->getSession()->get(SecurityContext::LAST_USERNAME),
|
||||
'error' => $error,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/login_check", name="_demo_security_check")
|
||||
*/
|
||||
public function securityCheckAction()
|
||||
{
|
||||
// The security layer will intercept this request
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/logout", name="_demo_logout")
|
||||
*/
|
||||
public function logoutAction()
|
||||
{
|
||||
// The security layer will intercept this request
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/hello", defaults={"name"="World"}),
|
||||
* @Route("/hello/{name}", name="_demo_secured_hello")
|
||||
* @Template()
|
||||
*/
|
||||
public function helloAction($name)
|
||||
{
|
||||
return array('name' => $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/hello/admin/{name}", name="_demo_secured_hello_admin")
|
||||
* @Security("is_granted('ROLE_ADMIN')")
|
||||
* @Template()
|
||||
*/
|
||||
public function helloadminAction($name)
|
||||
{
|
||||
return array('name' => $name);
|
||||
}
|
||||
}
|
||||
19
src/Acme/DemoBundle/Controller/WelcomeController.php
Normal file
19
src/Acme/DemoBundle/Controller/WelcomeController.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Acme\DemoBundle\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
|
||||
class WelcomeController extends Controller
|
||||
{
|
||||
public function indexAction()
|
||||
{
|
||||
/*
|
||||
* The action's view can be rendered using render() method
|
||||
* or @Template annotation as demonstrated in DemoController.
|
||||
*
|
||||
*/
|
||||
|
||||
return $this->render('AcmeDemoBundle:Welcome:index.html.twig');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user