I am trying to create a contact form in Symfony 2.4.1 and I get the following error:
Neither the property "contact" nor one of the methods "getContact()", "isContact()", "hasContact()", "__get()" exist and have public access in class "Open\OpcBundle\Entity\Contact".
I understand the error itself, but I canβt find the resources to fix it in the documentation for SF2 forms or on the Internet:
The controller code is as follows:
[..] class OpcController extends Controller { public function contactAction(Request $request) { $contact = new Contact(); $form = $this->createForm(new ContactType(), $contact); $form->handleRequest($request); return $this->render("OpenOpcBundle:Opc:contact.html.twig", array("formu" => $form->createView(), ) ); } }
The contact person is as follows:
[...] class Contact { protected $nom; protected $courriel; protected $sujet; protected $msg; public function getNom() { return $this->nom; } public function setNom($nom) { $this->nom = $nom; } public function getCourriel() { return $this->courriel; } public function setCourriel($courriel) { $this->courriel = $courriel; } public function getSujet() { return $this->sujet; } public function setSujet($sujet) { $this->sujet = $sujet; } public function getMsg() { return $this->msg; } public function setMsg($msg) { $this->msg = $msg; } }
And the code of the Form class:
public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('contact'); ->add('nom', 'text')) ->add('courriel', 'email') ->add('sujet', 'text') ->add('msg', 'textarea') ->add('submit', 'submit'); } public function getName() { return "Contact"; } public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array('data_class' => 'Open\OpcBundle\Entity\Contact', )); } }
Where is my mistake? thanks