Created
May 28, 2011 03:20
-
-
Save j/996556 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 JStout\MainBundle\Form\User; | |
use Symfony\Component\Form\Form; | |
class SignupHandler | |
{ | |
protected $form; | |
public function __construct(Form $form) | |
{ | |
$this->form = $form; | |
} | |
public function process() | |
{ | |
// Form validation successful!... :) | |
if ($this->form->isValid()) { | |
... do all the uber cool user signup stuff ... | |
} | |
// Form validation failed... :( | |
return false; | |
} | |
} |
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 JStout\MainBundle\Controller; | |
use Symfony\Bundle\FrameworkBundle\Controller\Controller, | |
Sensio\Bundle\FrameworkExtraBundle\Configuration\Route, | |
Sensio\Bundle\FrameworkExtraBundle\Configuration\Template, | |
JStout\MainBundle\Entity\User, | |
JStout\MainBundle\Form\User\SignupType, | |
JStout\MainBundle\Form\User\SignupHandler; | |
/** | |
* @Route("/user") | |
*/ | |
class UserController extends Controller | |
{ | |
/** | |
* @Route(name="user") | |
* @Template() | |
*/ | |
public function indexAction() | |
{ | |
return array(); | |
} | |
/** | |
* @Route("/sign-up", name="user_signup") | |
* @Template() | |
*/ | |
public function signupAction() | |
{ | |
$user = new User(); | |
$form = $this->get('form.factory')->create(new SignupType(), $user); | |
$request = $this->get('request'); | |
if ($request->getMethod() == 'POST') { | |
$form->bindRequest($request); | |
$formHandler = new SignupHandler($form); | |
if ($formHandler->process()) { | |
return $this->redirect($this->generateUrl('success'); | |
} | |
} | |
return array( | |
'form' => $form->createView() | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment