我想在seaparte文件中创建一个新表单(不在控制器中)。
这是创建带有实体的表单的示例:
<?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';
}
}
现在我想修改它并创建一个没有实体类的新表单。
那么,我能做什么?