Forked from anonymous/gist:9b78a9e840c034cb195c103db489d7e5
Last active
August 15, 2017 15:17
-
-
Save tarlepp/9656197b2758a154c6dc52f7a4361924 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Home\PageBundle\Handler; | |
use Symfony\Component\Form\Form; | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\HttpFoundation\RequestStack; | |
class BoxHandler | |
{ | |
protected $form; | |
protected $request; | |
public function __construct(Form $form, RequestStack $requestStack) | |
{ | |
$this->form = $form; | |
$this->request = $requestStack->getCurrentRequest(); | |
} | |
public function process() | |
{ | |
$this->form->handleRequest($this->request); | |
if ($this->form->isSubmitted() && $this->form->isValid()) | |
{ | |
return true; | |
} | |
return false; | |
} | |
public function onsucess() | |
{ | |
} | |
public function getForm() | |
{ | |
return $this->form; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class SomeController | |
{ | |
/** | |
* Creates a new box entity. | |
* | |
* @Route("/new", name="box_new") | |
* @Method({"GET", "POST"}) | |
*/ | |
public function newAction() | |
{ | |
$box = new Box(); | |
$form = $this->get('box_form'); | |
$boxhandler = $this->get('box_handler'); | |
if ($boxhandler->process()) { | |
$em = $this->getDoctrine()->getManager(); | |
$em->persist($box); | |
$em->flush(); | |
return $this->redirectToRoute('box_show', array('id' => $box->getId())); | |
} | |
return $this->render('box/new.html.twig', array( | |
'box' => $box, | |
'form' => $boxhandler->getForm()->createView(), | |
)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parameters: | |
class: Home\PageBundle\Entity\Box | |
services: | |
box_form: | |
class: Symfony\Component\Form\Form | |
factory: ['@form.factory', create ] | |
box_handler: | |
class: Home\PageBundle\Handler\BoxHandler | |
arguments: | |
- "@box_form" | |
- "@request_stack" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment