这可能很容易,但我是symfony2的新手,所以我想先问一下。我正在控制器中创建一个登录表单:
public function showAction()
{
$admin = new Administrator();
$form = $this->createFormBuilder($admin)->setAction($this->generateUrl('admin_login_process'))
->setMethod('POST')
->add('username', 'text')
->add('password', 'password')
->add('remember', 'checkbox')
->add('login', 'submit')
->getForm();
return $this->render('EraAdminBundle:Login:login.html.php', array('form'=>$form->createView()));
}
用户名和密码字段是管理员实体的一部分,但记住复选框当然不是。我如何与表格一起提交?因为如果我让它,因为它是我得到这个错误:
Neither the property "remember" nor one of the methods "getRemember()", "isRemember()", "hasRemember()", "__get()" or "__call()" exist and have public access in class "Era\RestoranteBundle\Entity\Administrator".
答案 0 :(得分:3)
阅读symfony 2 doc:http://symfony.com/doc/current/book/forms.html
在您的字段中(在formType中),您应该将“mapped”选项添加到“false”
$builder->add('task')
->add('dueDate', null, array('mapped' => false))
->add('save', 'submit');