Created
May 5, 2012 03:01
-
-
Save coreymcmahon/2599297 to your computer and use it in GitHub Desktop.
Usage of the Symfony form object in a Controller - http://www.symfonycentral.com
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 | |
/* ... rest of the controller */ | |
/** | |
* @Route("/article/add", name="post_add") | |
* @Template() | |
*/ | |
public function addAction() | |
{ | |
$form = $this->createFormBuilder() | |
->add('title', 'text') | |
->add('body', 'textarea') | |
->getForm(); | |
if ($this->getRequest()->getMethod() == 'POST') { | |
$form->bind($this->getRequest()->get('form')); | |
if ($form->isValid()) { | |
/* do stuff with the model in here... */ | |
} | |
} | |
return array('form' => $form->createView()); | |
} | |
/* ... rest of the controller */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment