我正在使用以下控制器代码在Symfony2上使用登录表单
public function loginAction(Request $request)
{
$user = new SiteUser();
$form = $this->createForm(new LoginType(), $user);
if ($request->getMethod() == 'POST') {
$form->bindRequest($request);
$data = $form->getValues();
// Need to do something with the data here
}
return $this->render('GDSiteBundle::header.html.twig', array('form' => $form->createView()));
}
但是我收到以下警告:
警告:array_replace_recursive()[function.array-replace-recursive]:参数#1不是\ vendor \ symfony \ src \ Symfony \ Component \ Form \ Form.php行中的数组593500内部服务器错误-ErrorException
有人可以帮助我了解什么不正确以及如何解决吗?谢谢。
更新:树枝文件是这样的:
<div class="form">
{{ form_errors(form) }}
<form action="{{ path('site_user_login') }}" method="POST" {{ form_enctype(form) }}>
<div class="level1">
{{ form_row(form.username) }}
<a href="javascript:void(0)" id="inscription">{% trans %}Registration{% endtrans %}</a>
</div>
<div class="level2">
{{ form_row(form.pwd_hash) }}
<div class="forget_pass"><a href="#" id="frgt">{% trans %}Forgot Password ?{% endtrans %}</a></div>
</div>
<input type="submit" class="submit" name="login" value/>
<div class="clr"></div>
</form>
</div>
这是表单类型中的函数
public function buildForm(FormBuilder $builder, array $options)
{
$builder->add('username', 'text', array('label' => 'Username : '));
$builder->add('pwd_hash','password', array('label' => 'Password : '));
}
这是路线:
site_user_login:
pattern: /{_locale}/login
defaults: {_controller: GDSiteBundle:SiteUser:login}