Skip to content

Instantly share code, notes, and snippets.

@coreymcmahon
Created May 5, 2012 05:54
Show Gist options
  • Select an option

  • Save coreymcmahon/2600205 to your computer and use it in GitHub Desktop.

Select an option

Save coreymcmahon/2600205 to your computer and use it in GitHub Desktop.
Defining a Symfony form in a separate class - http://www.symfonycentral.com
<?php
// src/MyCompany/BlogBundle/Form/Type/ArticleType.php
namespace MyCompany\BlogBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
class ArticleType extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder->add('title', 'text');
$builder->add('body', 'textarea');
}
public function getName()
{
/* The name should be a unique identifier for the form */
return 'article';
}
public function getDefaultOptions(array $options)
{
/* If this form corresponds to an Entity, we should include it here */
return array(
'data_class' => 'MyCompany\BlogBundle\Entity\Article',
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment