php - Symfony2 :Create form without entity within separate file
385
I'd like to create a new form into seaparte file ( not within controller ).
This is an example of creating a form with entity :
<?php
// src/OC/PlatformBundle/Form/AdvertType.php
namespace OC\PlatformBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class AdvertType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('date', 'date')
->add('title', 'text')
->add('author', 'text')
->add('content', 'textarea')
->add('published', 'checkbox', array('required' => false))
->add('save', 'submit')
;
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'OC\PlatformBundle\Entity\Advert'
));
}
public function getName()
{
return 'oc_platformbundle_advert';
}
}
I'd like now to modify it and create a new form without entity class.
So, what can i do ?
Answer
Solution:
Delete data_class assignment in setDefaultOptions() method and use this form without entity.