[英]Symfony2 form with field not in entity
這可能很容易,但我是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".
在閱讀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');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.