Symfony unifined CreateForm方法

时间:2016-12-27 15:13:10

标签: forms doctrine symfony-forms

我想生成一个表格来添加药剂,但他不认识这个方法

控制器

$public function addAction (Request $Request)
{
    $Medicament = new Medicament();

    $form = $this->
    createForm(ModeleType::class,$Medicament);
    $form->handleRequest($Request);
    if ($form->isValid())
    {
        $em=$this->getDoctrine()->getManager();
        $em->persist($Medicament);

        $em->flush();
        return $this->redirect($this->generateUrl(
            'Pharmacie_Medicament_Add'
        ));

    }

表格

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder->add('nom')->add('quantite')->add('datePeremption')->add('prix')
    ->add('save',SubmitType::class);
}

public function configureOptions(OptionsResolver $resolver)
{
    $resolver->setDefaults(array(
        'data_class' => 'PharmacieCentraleBundle\Entity\Medicament'
    ));
}

public function getBlockPrefix()
{
    return 'pharmaciecentralebundle_medicament';
}
  

尝试调用名为" createForm"的未定义方法。班级PharmacieCentraleBundle\Controller\MedicamentController

忽略这一点:kjetrzejkbfckzejvbkejvbkarebvnreblheabv eafvkljbeamjkvbelvbvbelvblb ealvberavhrve

1 个答案:

答案 0 :(得分:1)

createForm函数参数中,您需要传递MedicamentType的实例,而不是Medicament

参考:http://api.symfony.com/2.7/Symfony/Bundle/FrameworkBundle/Controller/Controller.html#method_createForm