Skip to content

Instantly share code, notes, and snippets.

@coreymcmahon
Created May 5, 2012 03:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coreymcmahon/2599297 to your computer and use it in GitHub Desktop.
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
<?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