即使我有createview(),Symfony 4错误呈现表格也是如此?

时间:2018-09-02 04:37:37

标签: php symfony4

我真的是Symfony 4的新手,但是我一直遵循指南here进行表单制作。我按照视频中的说明进行操作,但是无论出于什么原因,我都会得到错误

  

参数1传递给   Symfony \ Component \ Form \ FormRenderer :: renderBlock()必须是一个实例   Symfony \ Component \ Form \ FormView的字符串给出

并突出显示该行

  

'search_form'=> $ form-> createView(),

我正在努力解决这个问题,因为一切都说我需要执行createView()...但是我正在这样做。我想念什么?下面的代码:

PatientSearchController.php:

<?php

namespace App\Controller;

use App\Form\PatientSearchType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;

class PatientSearchController extends AbstractController
{
    /**
     * @Route("/patient/search", name="patient_search")
     */
    public function index()
    {
        $form = $this->createForm(PatientSearchType::class);

        return $this->render('patient_search/index.html.twig', [
            'search_form' => $form->createView(),
        ]);
    }
}

Patient_search / index.html.twig:

{% extends 'base.html.twig' %}

{% block body %}

    {{ form_start('search_form') }}
    {{ form_widget('search_form') }}
    {{ form_end('search_form') }}
{% endblock %}

PatientSearchType:

<?php

namespace App\Form;

use App\Entity\Patients;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class PatientSearchType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('PatientId')
            ->add('Address1')
            ->add('Address2')
            ->add('City')
            ->add('State')
            ->add('Phone1')
            ->add('Phone2')
            ->add('Email')
            ->add('DateOfBirth')
            ->add('InsuranceId')
            ->add('InsuranceNo')
        ;
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'data_class' => Patients::class,
        ]);
    }
}

0 个答案:

没有答案