Symfony2表单中的字段不在实体中

5

这可能很简单,但我还是新手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".
1个回答

3

阅读Symfony 2文档:http://symfony.com/doc/current/book/forms.html

在您的领域(在formType中),您应该将选项“mapped”添加为“false”。

$builder->add('task')
    ->add('dueDate', null, array('mapped' => false))
    ->add('save', 'submit');

我想象它很容易,但是我错过了文档的那一部分 :) - domenikk

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接