Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 form with field not in entity

this may be very easy but i'm new to symfony2, so i thought asking first. i'm creating a login form in a 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()));
}

the username and password fields are part of the administrator entity, but the remember checkbox is not of course. how do i submit it together with the form? cause if i let it as it is 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".
like image 258
domenikk Avatar asked Oct 20 '22 19:10

domenikk


1 Answers

In reading the 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');
like image 184
BENARD Patrick Avatar answered Oct 24 '22 11:10

BENARD Patrick