这真的很奇怪,它发生在更新 Twig 模板之后:
控制器部分
$registration = new Registration();
$form = $this->createForm(new RegistrationType(), $registration, array(
'action' => $this->generateUrl('account_create'),
));
return $this->render(
'AcmeCommonBundle:Security:register.html.twig',
array(
'form' => $form->createView(),
'contentBackColor' => 'canvasGreen'
)
);
模板部分
{{ form_start(form) }}
{{ form_errors(form) }}
<p>All Fields Are Required</p>
<div class="form-row">
{{ form_label(form.firstname, "First Name") }}
{{ form_widget(form.firstname) }}
<div class="clear-fix"></div>
</div>
<div class="form-errors-row">
{{ form_errors(form.firstname) }}
</div>
<div class="form-row">
{{ form_label(form.lastname, "Last Name") }}
{{ form_widget(form.lastname) }}
<div class="clear-fix"></div>
</div>
<div class="form-errors-row">
{{ form_errors(form.lastname) }}
</div>
<div class="form-row">
{{ form_label(form.username, "Username") }}
{{ form_widget(form.username) }}
<div class="clear-fix"></div>
</div>
<div class="form-errors-row">
{{ form_errors(form.username) }}
</div>
<div class="form-row">
{{ form_label(form.email, "Email") }}
{{ form_widget(form.email) }}
<div class="clear-fix"></div>
</div>
<div class="form-errors-row">
{{ form_errors(form.email) }}
</div>
<div class="form-row">
{{ form_label(form.password, "Password") }}
{{ form_widget(form.password) }}
<div class="clear-fix"></div>
</div>
<div class="form-errors-row">
{{ form_errors(form.password) }}
</div>
<div class="form-row">
{{ form_label(form.confirm, "Confirm Password") }}
{{ form_widget(form.confirm) }}
<div class="clear-fix"></div>
</div>
<div class="form-errors-row">
{{ form_errors(form.confirm) }}
</div>
<div class="form-row">
{{ form_label(form.terms, "Terms & Conditions") }}
{{ form_widget(form.terms) }}
<div class="clear-fix"></div>
</div>
<div class="form-errors-row">
{{ form_errors(form.terms) }}
</div>
{{ form_end(form) }}
错误
Argument 1 passed to Symfony\Component\Form\FormRenderer::searchAndRenderBlock() must be an instance of Symfony\Component\Form\FormView, null given
如您所见,我确实在渲染 FormView,它为 null 的事实让我相信这与 RegistrationType() 类有关,但那里没有任何变化,只是在要渲染的模板中?