gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-10-31 23:20:55 24 4
gpt4 key购买 nike

这可能很简单,但我是 symfony2 的新手,所以我想先问问。我正在 Controller 中创建一个登录表单:

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".

最佳答案

在阅读 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');

关于php - 字段不在实体中的 Symfony2 表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20458094/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com