symfony - AppBundle\\Entity\\User#$class_cat\", got \"integer\" instead -


hi got error while data insert in database please let me know problem new in symfony

"expected value of type \"appbundle\entity\class_cat\" association field \"appbundle\entity\user#$class_cat\", got \"integer\" instead.", "class": "doctrine\orm\orminvalidargumentexception"

this user entity

namespace appbundle\entity;  use doctrine\orm\mapping orm;  /**  * user  *  * @orm\table(name="user")  * @orm\entity(repositoryclass="appbundle\repository\userrepository")  */ class user {     /**      * constructor      */     public function __construct()     {         $this->class_cat = new \doctrine\common\collections\arraycollection();     }      /**      * @var int      *      * @orm\column(name="id", type="integer")      * @orm\id      * @orm\generatedvalue(strategy="auto")      */     private $id;      /**      * @var string      *      * @orm\column(name="name", type="string", length=255)      */     private $name;      /**      * @var string      *      * @orm\column(name="role", type="string", length=255)      */     private $role;       /**      * @orm\manytoone(targetentity="class_cat", inversedby="users")      * @orm\joincolumn(name="class_id", referencedcolumnname="id")      */     private $class_cat;      /**      * id      *      * @return int      */     public function getid()     {         return $this->id;     }      /**      * set name      *      * @param string $name      *      * @return user      */     public function setname($name)     {         $this->name = $name;          return $this;     }      /**      * name      *      * @return string      */     public function getname()     {         return $this->name;     }      /**      * set role      *      * @param string $role      *      * @return user      */     public function setrole($role)     {         $this->role = $role;          return $this;     }      /**      * role      *      * @return string      */     public function getrole()     {         return $this->role;     }      /**      * @return mixed      */     public function getclasscat()     {         return $this->class_cat;     }      /**      * @param mixed $class_cat      */     public function setclasscat($class_cat)     {         $this->class_cat = $class_cat;     } 

this class_cat enity

class class_cat {      /**      * constructor      */     public function __construct()     {         $this->users = new \doctrine\common\collections\arraycollection();     }      /**      * @var int      *      * @orm\column(name="id", type="integer")      * @orm\id      * @orm\generatedvalue(strategy="auto")      */     private $id;      /**      * @var string      *      * @orm\column(name="class_name", type="string", length=255)      */     private $classname;      /**      * @orm\onetomany(targetentity="user", mappedby="class_cat")      */     protected $users;      /**      * id      *      * @return int      */     public function getid()     {         return $this->id;     }      /**      * set classname      *      * @param string $classname      *      * @return class_cat      */     public function setclassname($classname)     {         $this->classname = $classname;          return $this;     }      /**      * classname      *      * @return string      */     public function getclassname()     {         return $this->classname;     }       public function getusers()     {         return $this->users;     }      /**      * @param mixed $users      */     public function setusers($users)     {         $this->users = $users;     } 

this controller code

>  public function postaction(request $request) >     { >         $data = new user; >         $name = $request->get('name'); >         $role = $request->get('role'); >         $class = $request->get('class_id'); >         if (empty($name) || empty($role) || empty($class)) { >             return new view("null values not allowed", response::http_not_acceptable); >         } >         $data->setname($name); >         $data->setrole($role); >         $data->setclassid(1); >         $em = $this->getdoctrine()->getmanager(); >         $em->persist($data); >         $em->flush(); >         return new view("user added successfully", response::http_ok); >     } 

you need pass entity not id example:

$em = $this->getdoctrine()->getmanager(); $classcat = $em->getrepository('appbundle:classcat')->find(1); $data->setclasscat($classcat); 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -