我尝试与Symfony 2.4.1做一个联系表单,我有以下错误:
Neither the property "contact" nor one of the methods "getContact()", "isContact()", "hasContact()", "__get()" exist and have public access in class "Open\OpcBundle\Entity\Contact".
Run Code Online (Sandbox Code Playgroud)
我理解这个错误,但我发现在SF2表单文档或Web上有任何解决方法:
控制器代码是:
[..]
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(),
)
);
}
}
Run Code Online (Sandbox Code Playgroud)
联系实体是:
[...]
class Contact {
protected $nom;
protected $courriel;
protected $sujet;
protected $msg;
public function getNom() {
return $this->nom;
}
public function setNom($nom) {
$this->nom …Run Code Online (Sandbox Code Playgroud)