Php 如何解决ContextErrorException:可捕获致命错误:

Php 如何解决ContextErrorException:可捕获致命错误:,php,forms,symfony,twig,Php,Forms,Symfony,Twig,我正在使用symfony2。实际上,我已经使用表单类型创建了表单。但是当我呈现表单时,出现了以下错误 ContextErrorException:可捕获的致命错误:传递给Symfony\Component\Form\FormRenderer::SearchandEnderBlock()的参数1必须是Symfony\Component\Form\FormView的实例 这是我的密码 控制器 $profile = new profile(); $myForm = $this->createFo

我正在使用symfony2。实际上,我已经使用表单类型创建了表单。但是当我呈现表单时,出现了以下错误

ContextErrorException:可捕获的致命错误:传递给Symfony\Component\Form\FormRenderer::SearchandEnderBlock()的参数1必须是Symfony\Component\Form\FormView的实例

这是我的密码

控制器

$profile = new profile();
$myForm = $this->createForm(new ProfileFormType(), $profile);
return $this->render('ProfileBundle:Profle:profile.html.twig', array(
    'form' => $myForm,
    'vendor' => $vendor,
    'productId' => $productId
));
profile.twig.html

<form action="{{ path('profile_new') }}" method="POST" {{ form_enctype(form) }} id="frmProfile">

    <div class="box-body col-sm-6">
        <div class="form-group">
            <label class="control-label">First Name: </label>
            {{ form_widget(form.firstName, { 'attr': { 'placeholder': 'Title', 'class': 'form-control'}}) }}
            <div class="serverError">{{ form_errors(form.firstName) }}</div>
        </div>
    </div>

    <div class="box-body col-sm-6">
        <div class="form-group">
            <label class="control-label">Last Name: </label>
            {{ form_widget(form.lastName, { 'attr': { 'placeholder': 'Title', 'class': 'form-control'}}) }}
            <div class="serverError">{{ form_errors(form.lastName) }}</div>
        </div>
    </div>

    <div class="box-body col-sm-6">
        <div class="form-group">
            <label class="control-label">User Name: </label>
            {{ form_widget(form.username, { 'attr': { 'placeholder': 'Title', 'class': 'form-control'}}) }}
            <div class="serverError">{{ form_errors(form.username) }}</div>
        </div>
    </div>
</form>

名字:
{{form_小部件(form.firstName,{'attr':{'placeholder':'Title','class':'formcontrol'}}}}}
{{form_errors(form.firstName)}}
姓氏:
{{form_小部件(form.lastName,{'attr':{'placeholder':'Title','class':'formcontrol'}}}}}
{{form_errors(form.lastName)}}
用户名:
{{form_小部件(form.username,{'attr':{'placeholder':'Title','class':'form control'}}}}}
{{form_errors(form.username)}}

我做错了什么?

'form'=>$myForm
替换为
'form'=>$myForm->createView()
。函数
createView()
将创建表单对象的视图

return $this->render('ProfileBundle:Profle:profile.html.twig', array(
    'form' => $myForm->createView(),  // << Add "->createView()"
    'vendor' => $vendor,
    'productId' => $productId
));
return$this->render('ProfileBundle:profile:profile.html.twig',数组(
'form'=>$myForm->createView(),//$vendor,
“productId”=>$productId
));
$myForm->createView()