Symfony2 form with field not in essence

It can be very easy, but I'm new to symfony2, so I thought it first when asking. I create a login form for the 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()));
}

Username and password fields are part of the admin object, but the checkbox is optional. How can I submit it along with the form? because if I do this, I get this error:

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".
+4
source share
1 answer

When reading symfony 2 doc: http://symfony.com/doc/current/book/forms.html

In your field (in formType) you should add the option "mapped" to "false"

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

All Articles