Created
May 7, 2012 12:15
-
-
Save coreymcmahon/2627464 to your computer and use it in GitHub Desktop.
Using validators on a form object - http://www.symfonycentral.com/symfony-does-validation.html
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 | |
use MyCompany\BlogBundle\Entity\Article; | |
use MyCompany\BlogBundle\Form\ArticleType; | |
use Symfony\Component\HttpFoundation\Request; | |
/* ... rest of the controller */ | |
public function updateAction(Request $request) | |
{ | |
$article = new Article(); | |
/* Create the form, add the article object */ | |
$form = $this->createForm(new ArticleType(), $article); | |
if ($request->getMethod() == 'POST') { | |
/* This is where we handle the postback... */ | |
$form->bindRequest($request); | |
if ($form->isValid()) { | |
/* Data is valid, do something in here*/ | |
} else { | |
/* Data is invalid, do do something in here */ | |
} | |
} | |
} | |
/* rest of the controller... */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment