php - Error in Symfony 2 when create object of child entity class -


i have file /src/appbundle/entity/questionnaire.php 3 entity classes, i'm trying implement single table inheritance doctrine 2 on symfony 2.7. questionnaire parent abstract class, , there 2 child classes firstquestions , secondsquestions extends questionnaire. choosed model because need write data in table in 2 steps. code of file below:

namespace appbundle\entity;  use doctrine\orm\mapping orm;  /**  * questionnaire  *  * @orm\entity  * @orm\table(name="questionnaire")  * @orm\inheritancetype("single_table")  * @orm\discriminatorcolumn(name="discr", type="string")  * @orm\discriminatormap({"firstquestions" = "firstquestions", "secondquestions" = "secondquestions"})  */ abstract class questionnaire {     /**      * @var integer      *      * @orm\column(name="id", type="integer")      * @orm\id      * @orm\generatedvalue(strategy="auto")      */     private $id;      /**      * id      *      * @return integer      */     public function getid()     {         return $this->id;     } }  /**  * firstquestions  */ class firstquestions extends questionnaire {     /**      * @var string      *      * @orm\column(name="firstname", type="string", length=64)      */     private $firstname;      /**      * @var string      *      * @orm\column(name="lastname", type="string", length=64)      */     private $lastname;      /**      * @var string      *      * @orm\column(name="email", type="string", length=32)      */     private $email;      /**      * @var \datetime      *      * @orm\column(name="birthday", type="date")      */     private $birthday;      /**      * @var integer      *      * @orm\column(name="shoesize", type="integer")      */     private $shoesize;      /**      * set firstname      *      * @param string $firstname      *      * @return questionnaire      */     public function setfirstname($firstname)     {         $this->firstname = $firstname;          return $this;     }      /**      * firstname      *      * @return string      */     public function getfirstname()     {         return $this->firstname;     }      /**      * set lastname      *      * @param string $lastname      *      * @return questionnaire      */     public function setlastname($lastname)     {         $this->lastname = $lastname;          return $this;     }      /**      * lastname      *      * @return string      */     public function getlastname()     {         return $this->lastname;     }      /**      * set email      *      * @param string $email      *      * @return questionnaire      */     public function setemail($email)     {         $this->email = $email;          return $this;     }      /**      * email      *      * @return string      */     public function getemail()     {         return $this->email;     }      /**      * set birthday      *      * @param \datetime $birthday      *      * @return questionnaire      */     public function setbirthday($birthday)     {         $this->birthday = $birthday;          return $this;     }      /**      * birthday      *      * @return \datetime      */     public function getbirthday()     {         return $this->birthday;     }      /**      * set shoesize      *      * @param integer $shoesize      *      * @return questionnaire      */     public function setshoesize($shoesize)     {         $this->shoesize = $shoesize;          return $this;     }      /**      * shoesize      *      * @return integer      */     public function getshoesize()     {         return $this->shoesize;     } }  /**  * secondquestions  */ class secondquestions extends questionnaire {     /**      * @var string      *      * @orm\column(name="favoriteicecream", type="string", length=128)      */     private $favoriteicecream;      /**      * @var string      *      * @orm\column(name="favoritesuperhero", type="string", length=32)      */     private $favoritesuperhero;      /**      * @var string      *      * @orm\column(name="favoritemoviestar", type="string", length=64)      */     private $favoritemoviestar;      /**      * @var \datetime      *      * @orm\column(name="endoftheworld", type="date")      */     private $endoftheworld;      /**      * @var string      *      * @orm\column(name="superbowlwinner", type="string", length=32)      */     private $superbowlwinner;      /**      * set favoriteicecream      *      * @param string $favoriteicecream      *      * @return questionnaire      */     public function setfavoriteicecream($favoriteicecream)     {         $this->favoriteicecream = $favoriteicecream;          return $this;     }      /**      * favoriteicecream      *      * @return string      */     public function getfavoriteicecream()     {         return $this->favoriteicecream;     }      /**      * set favoritesuperhero      *      * @param string $favoritesuperhero      *      * @return questionnaire      */     public function setfavoritesuperhero($favoritesuperhero)     {         $this->favoritesuperhero = $favoritesuperhero;          return $this;     }      /**      * favoritesuperhero      *      * @return string      */     public function getfavoritesuperhero()     {         return $this->favoritesuperhero;     }      /**      * set favoritemoviestar      *      * @param string $favoritemoviestar      *      * @return questionnaire      */     public function setfavoritemoviestar($favoritemoviestar)     {         $this->favoritemoviestar = $favoritemoviestar;          return $this;     }      /**      * favoritemoviestar      *      * @return string      */     public function getfavoritemoviestar()     {         return $this->favoritemoviestar;     }      /**      * set endoftheworld      *      * @param \datetime $endoftheworld      *      * @return questionnaire      */     public function setendoftheworld($endoftheworld)     {         $this->endoftheworld = $endoftheworld;          return $this;     }      /**      * endoftheworld      *      * @return \datetime      */     public function getendoftheworld()     {         return $this->endoftheworld;     }      /**      * set superbowlwinner      *      * @param string $superbowlwinner      *      * @return questionnaire      */     public function setsuperbowlwinner($superbowlwinner)     {         $this->superbowlwinner = $superbowlwinner;          return $this;     }      /**      * superbowlwinner      *      * @return string      */     public function getsuperbowlwinner()     {         return $this->superbowlwinner;     } } 

so problem when i'm trying create object of child class(firstquestions or secondsquestions) in method of controller, symfony displays me error "500 internal server error". code of controller method below:

namespace appbundle\controller;  use symfony\bundle\frameworkbundle\controller\controller; use sensio\bundle\frameworkextrabundle\configuration\route; use symfony\component\httpfoundation\response; use symfony\component\httpfoundation\request; use appbundle\entity\questionnaire; use appbundle\entity\firstquestions; use appbundle\entity\secondquestions;  class testcontroller extends controller {      /**      * @route("/test", name="test")      */     public function indexaction(request $request)     {         $item = new firstquestions(); // works without line         return new response(             'ok'         );     } } 

maybe doing wrong or didn't set important annotation. can me?

this 1 of annoying little oversight errors - semi-colon or somewhere you're not looking it. i'm creating additional answer can give code i'm using. hopefully, you'll able cut-and-paste, replace own files new code, , magically start working.

first - prove point, here's (modified) output:

veromo\bundle\corebundle\entity\firstquestions object (     [firstname:veromo\bundle\corebundle\entity\firstquestions:private] =>      [lastname:veromo\bundle\corebundle\entity\firstquestions:private] =>      [email:veromo\bundle\corebundle\entity\firstquestions:private] =>      [birthday:veromo\bundle\corebundle\entity\firstquestions:private] =>      [shoesize:veromo\bundle\corebundle\entity\firstquestions:private] =>      [id:veromo\bundle\corebundle\entity\questionnaire:private] =>  ) 

which shows i'm doing differently using own dev environment's namespaces.

appbundle\entity\questionnaire.php

<?php  namespace appbundle\entity;  use doctrine\orm\mapping orm;  /**  * questionnaire  *  * @orm\entity  * @orm\table(name="questionnaire")  * @orm\inheritancetype("single_table")  * @orm\discriminatorcolumn(name="discr", type="string")  * @orm\discriminatormap({"questionnaire"="questionnaire", "firstquestions" = "firstquestions", "secondquestions" = "secondquestions"})  */ abstract class questionnaire {     /**      * @var integer      *      * @orm\column(name="id", type="integer")      * @orm\id      * @orm\generatedvalue(strategy="auto")      */     private $id;      /**      * id      *      * @return integer      */     public function getid()     {         return $this->id;     } } 

appbundle\entity\firstquestions.php

<?php  namespace appbundle\entity;  use doctrine\orm\mapping orm;  /**  * firstquestions  * @orm\entity()  */ class firstquestions extends questionnaire {     /**      * @var string      *      * @orm\column(name="firstname", type="string", length=64)      */     private $firstname;      /**      * @var string      *      * @orm\column(name="lastname", type="string", length=64)      */     private $lastname;      /**      * @var string      *      * @orm\column(name="email", type="string", length=32)      */     private $email;      /**      * @var \datetime      *      * @orm\column(name="birthday", type="date")      */     private $birthday;      /**      * @var integer      *      * @orm\column(name="shoesize", type="integer")      */     private $shoesize;      /**      * set firstname      *      * @param string $firstname      *      * @return questionnaire      */     public function setfirstname($firstname)     {         $this->firstname = $firstname;          return $this;     }      /**      * firstname      *      * @return string      */     public function getfirstname()     {         return $this->firstname;     }      /**      * set lastname      *      * @param string $lastname      *      * @return questionnaire      */     public function setlastname($lastname)     {         $this->lastname = $lastname;          return $this;     }      /**      * lastname      *      * @return string      */     public function getlastname()     {         return $this->lastname;     }      /**      * set email      *      * @param string $email      *      * @return questionnaire      */     public function setemail($email)     {         $this->email = $email;          return $this;     }      /**      * email      *      * @return string      */     public function getemail()     {         return $this->email;     }      /**      * set birthday      *      * @param \datetime $birthday      *      * @return questionnaire      */     public function setbirthday($birthday)     {         $this->birthday = $birthday;          return $this;     }      /**      * birthday      *      * @return \datetime      */     public function getbirthday()     {         return $this->birthday;     }      /**      * set shoesize      *      * @param integer $shoesize      *      * @return questionnaire      */     public function setshoesize($shoesize)     {         $this->shoesize = $shoesize;          return $this;     }      /**      * shoesize      *      * @return integer      */     public function getshoesize()     {         return $this->shoesize;     } } 

appbundle\entity\secondquestions.php

<?php  namespace appbundle\entity;  use doctrine\orm\mapping orm;  /**  * secondquestions  * @orm\entity()  */ class secondquestions extends questionnaire {     /**      * @var string      *      * @orm\column(name="favoriteicecream", type="string", length=128)      */     private $favoriteicecream;      /**      * @var string      *      * @orm\column(name="favoritesuperhero", type="string", length=32)      */     private $favoritesuperhero;      /**      * @var string      *      * @orm\column(name="favoritemoviestar", type="string", length=64)      */     private $favoritemoviestar;      /**      * @var \datetime      *      * @orm\column(name="endoftheworld", type="date")      */     private $endoftheworld;      /**      * @var string      *      * @orm\column(name="superbowlwinner", type="string", length=32)      */     private $superbowlwinner;      /**      * set favoriteicecream      *      * @param string $favoriteicecream      *      * @return questionnaire      */     public function setfavoriteicecream($favoriteicecream)     {         $this->favoriteicecream = $favoriteicecream;          return $this;     }      /**      * favoriteicecream      *      * @return string      */     public function getfavoriteicecream()     {         return $this->favoriteicecream;     }      /**      * set favoritesuperhero      *      * @param string $favoritesuperhero      *      * @return questionnaire      */     public function setfavoritesuperhero($favoritesuperhero)     {         $this->favoritesuperhero = $favoritesuperhero;          return $this;     }      /**      * favoritesuperhero      *      * @return string      */     public function getfavoritesuperhero()     {         return $this->favoritesuperhero;     }      /**      * set favoritemoviestar      *      * @param string $favoritemoviestar      *      * @return questionnaire      */     public function setfavoritemoviestar($favoritemoviestar)     {         $this->favoritemoviestar = $favoritemoviestar;          return $this;     }      /**      * favoritemoviestar      *      * @return string      */     public function getfavoritemoviestar()     {         return $this->favoritemoviestar;     }      /**      * set endoftheworld      *      * @param \datetime $endoftheworld      *      * @return questionnaire      */     public function setendoftheworld($endoftheworld)     {         $this->endoftheworld = $endoftheworld;          return $this;     }      /**      * endoftheworld      *      * @return \datetime      */     public function getendoftheworld()     {         return $this->endoftheworld;     }      /**      * set superbowlwinner      *      * @param string $superbowlwinner      *      * @return questionnaire      */     public function setsuperbowlwinner($superbowlwinner)     {         $this->superbowlwinner = $superbowlwinner;          return $this;     }      /**      * superbowlwinner      *      * @return string      */     public function getsuperbowlwinner()     {         return $this->superbowlwinner;     } } 

appbundle\controller\testcontroller.php

<?php  namespace appbundle\controller;  use symfony\bundle\frameworkbundle\controller\controller; use sensio\bundle\frameworkextrabundle\configuration\route; use symfony\component\httpfoundation\response; use symfony\component\httpfoundation\request; use appbundle\entity\questionnaire; use appbundle\entity\firstquestions; use appbundle\entity\secondquestions;  class testcontroller extends controller {     /**      * @route("/test",name="test")      */     public function indexaction( request $request )     {         $item = new firstquestions();         return new response(             '<pre>'.print_r( $item, true ).'</pre>'         );     } } 

and sure ...

app\config\routing.yml

test:     resource:   "@appbundle/controller/testcontroller.php"     type:       annotation 

it's got stupid, annoying little error nobody looking for.

hope helps ...


Comments