php - Symfony3 - "Unrecognized field" exception when I want to pull entries based on the value of a Many-to-One relation property -
want display records entity, records have loginid value equal current user's id. in events entity, loginid many-to-one property.
have following events entity:
namespace vendor\mybundle\entity; use doctrine\orm\mapping orm; use symfony\component\httpfoundation\file\uploadedfile; use symfony\component\validator\constraints assert; /** * events * * @orm\table(name="events") * @orm\entity */ class events { /** * @var string * * @orm\column(name="eventname", type="string", length=255, nullable=false) */ private $eventname; /** * @var string * * @orm\column(name="location", type="string", length=255, nullable=false) */ private $location; /** * @var \datetime * * @orm\column(name="startdate", type="datetime", nullable=false) */ private $startdate; /** * @var \datetime * * @orm\column(name="enddate", type="datetime", nullable=false) */ private $enddate; /** * @var boolean * * @orm\column(name="status", type="boolean", nullable=false) */ private $status; /** * @var integer * * @orm\column(name="eventid", type="integer") * @orm\id * @orm\generatedvalue(strategy="identity") */ private $eventid; /** * set eventname * * @param string $eventname * * @return events */ public function seteventname($eventname) { $this->eventname = $eventname; return $this; } /** * eventname * * @return string */ public function geteventname() { return $this->eventname; } /** * set location * * @param string $location * * @return events */ public function setlocation($location) { $this->location = $location; return $this; } /** * location * * @return string */ public function getlocation() { return $this->location; } /** * set startdate * * @param \datetime $startdate * * @return events */ public function setstartdate($startdate) { $this->startdate = $startdate; return $this; } /** * startdate * * @return \datetime */ public function getstartdate() { return $this->startdate; } /** * set enddate * * @param \datetime $enddate * * @return events */ public function setenddate($enddate) { $this->enddate = $enddate; return $this; } /** * enddate * * @return \datetime */ public function getenddate() { return $this->enddate; } /** * set status * * @param boolean $status * * @return events */ public function setstatus($status) { $this->status = $status; return $this; } /** * status * * @return boolean */ public function getstatus() { return $this->status=true; } /** * eventid * * @return integer */ public function geteventid() { return $this->eventid; } /** * web path upload directory. * * @return string * relative path. */ protected function getuploadpath() { return 'uploads/eventcovers'; } /** * absolute path. * * @return string * absolute path. */ protected function getuploadabsolutepath() { return __dir__ . '/../../../../web/' . $this->getuploadpath(); } /** * web path cover. * * @return null|string * relative path. */ public function getcoverweb() { return null === $this->getcover() ? null : $this->getuploadpath() . '/' . $this->getcover(); } /** * web path on disk cover. * * @return null|string * absolute path. */ public function getcoverabsolute() { return null === $this->getcover() ? null : $this->getuploadabsolutepathpath() . '/' . $this->getcover(); } /** * set validation max file size of 2 mb. * * @assert\file(maxsize="2m") */ private $file; /** * sets file. * * @param uploadedfile $file */ public function setfile(uploadedfile $file = null) { $this->file = $file; } /** * file. * * @return uploadedfile */ public function getfile() { return $this->file; } /** * * upload cover file. */ public function upload() { //file property can empty if (null === $this->getfile()){ return; } $filename=$this->getfile()->getclientoriginalname(); //move uploaded file target directory using original name $this->getfile()->move( $this->getuploadabsolutepath(), $filename); //set cover $this->setcover($filename); //cleanup $this->setfile(); } /** * @var string * * @orm\column(name="cover", type="string", length=255, nullable=true) */ private $cover; /** * set cover * * @param string $cover * * @return events */ public function setcover($cover) { $this->cover = $cover; return $this; } /** * cover * * @return string */ public function getcover() { return $this->cover; } /** * @var \vendor\mybundle\entity\logins */ private $loginid; /** * @var \vendor\mybundle\entity\wishlist */ private $wishlistid; /** * set loginid * * @param \vendor\mybundle\entity\logins $loginid * * @return events */ public function setloginid(\vendor\mybundle\entity\logins $loginid = null) { $this->loginid = $loginid; return $this; } /** * loginid * * @return \vendor\mybundle\entity\logins */ public function getloginid() { return $this->loginid; } /** * set wishlistid * * @param \vendor\mybundle\entity\wishlist $wishlistid * * @return events */ public function setwishlistid(\vendor\mybundle\entity\wishlist $wishlistid = null) { $this->wishlistid = $wishlistid; return $this; } /** * wishlistid * * @return \vendor\mybundle\entity\wishlist */ public function getwishlistid() { return $this->wishlistid; } }
and following indexaction in controller:
namespace vendor\mybundle\controller; use symfony\component\httpfoundation\request; use symfony\bundle\frameworkbundle\controller\controller; use sensio\bundle\frameworkextrabundle\configuration\method; use sensio\bundle\frameworkextrabundle\configuration\route; use vendor\mybundle\entity\events; use vendor\mybundle\form\eventstype; /** * events controller. * * @route("/sec/events") */ class eventscontroller extends controller { /** * lists events entities. * * @route("/", name="sec_events_index") * @method("get") */ public function indexaction() { $em = $this->getdoctrine()->getmanager(); $user = $this->getuser(); $events = $em->getrepository('vendormybundle:events')->findby(array('loginid' => $user->getloginid())); return $this->render('events/index.html.twig', array( 'events' => $events, )); } }
however thrown error: unrecognized field: loginid though name of field/property in events class.
looked here , have code used says in there.
missing?
appreciated!
you missing orm definition $loginid
, because of there no column loginid in events table.
i assume want have onetomany or manytomany association ...\entity\logins
, have define association according this: http://doctrine-orm.readthedocs.org/projects/doctrine-orm/en/latest/reference/association-mapping.html
Comments
Post a Comment