I am new to Symfony and learning Symfony2 by creating a small project.
/** UserType buildform function */
$age_choices = array('18'=>'18+','25'=>'25+','30'=>'30+','40'=>'40+','50'=>'50+');
$complextion_choices = array('Moderate'=>'Moderate','Fair'=>'Fair');
$builder
->add('first_name', 'text')
->add('last_name', 'text')
->add('email', 'text')
->add('phone', 'text', array('required' => false))
->add('age', 'choice', array('choices' => $age_choices) )
->add('complextion', 'choice', array('choices' => $complextion_choices) );
/** Creating user form ***/**
$user = new Users();
$form = $this->createForm(new UsersType());
return $this->render('TrytillUserBundle:User:signup.html.twig', array('form' =>
$form->createView()));
Now When I submit this form.. getting it using following way.
$user = new Users();
$form = $this->createForm(new UsersType(), $user);
$form->bindRequest($request);
if ($form->isValid()) {
/// some task here.
}
return $this->render('TrytillUserBundle:User:signup.html.twig', array('form' => $form->createView()));
The problem is that on bindRequest line it saying me that property first_name doesn’t exist in Entity Users.
I have created Users Entity using doctrine and it’s private $firstName in Entity/Users.php
Thanks for any help.
Try
->add('firstName', 'text')instead of->add('first_name', 'text')in yourUserType::buildFormfunction, same goes forlast_name.