symfony - Symfony2 - Validation for form with multiple entities not working -


i have form product relation onetomany entity productlocale , user can add many productlocale want.

the rendered form in html seems correct when receive post array , perform bind() server response error:

"error: value should of type wearplay\wearbundle\entity\productlocale. 

but send 2 productlocale entities , validator doesn't recognize them.

it obvious post request contains multi-dimensional array contains various entities productlocale, question why

$form->bindrequest($request) 

doesn't work correctly?

edit #1:

product entity

<?php  namespace wearplay\wearbundle\entity;  use doctrine\orm\mapping orm; use doctrine\common\collections\arraycollection; use symfony\component\validator\constraints assert;  /** * @orm\entity * @orm\haslifecyclecallbacks * @orm\table(name="product") */  class product {     /**     * @orm\id     * @orm\column(type="integer")     * @orm\generatedvalue(strategy="auto")     */     private $id;      /**      *@orm\column(type="string")      */     private $name;      /**       * @orm\manytoone(targetentity="brandowner", cascade="persist")       */     private $owner;      /**      * @orm\column(name="creation_date", type="datetime", nullable=false)      */     private $creationdate;      /**      * @assert\type(type="wearplay\wearbundle\entity\productlocale")      */     protected $productlocales;      /**      * @assert\type(type="wearplay\wearbundle\entity\productpic")      */     protected $productpic;      public function __construct()     {         $this->productlocales = new arraycollection();     }      /**       * @orm\prepersist      */      public function createtimestamps()     {         $this->creationdate = new \datetime(date('y-m-d h:i:s'));     }      /**      * id      *      * @return integer       */     public function getid()     {         return $this->id;     }      /**      * set name      *      * @param string $name      * @return product      */     public function setname($name)     {         $this->name = $name;          return $this;     }      /**      * name      *      * @return string       */     public function getname()     {         return $this->name;     }      /**      * creationdate      *      * @return \datetime       */     public function getcreationdate()     {         return $this->creationdate;     }      /**      * set owner      *      * @param \wearplay\wearbundle\entity\brandowner $owner      * @return product      */     public function setowner(\wearplay\wearbundle\entity\brandowner $owner = null)     {         $this->owner = $owner;          return $this;     }      /**      * owner      *      * @return \wearplay\wearbundle\entity\brandowner       */     public function getowner()     {         return $this->owner;     }       /**      * productlocales      *      * @return \wearplay\wearbundle\entity\productlocale       */     public function getproductlocales()     {         return $this->productlocales;     }      /**      * set productlocale      *      * @param \wearplay\wearbundle\entity\productlocale $productlocale      * @return product      */     public function setproductlocales(arraycollection $productlocales = null)     {         $this->productlocales = $productlocales;          //return $this->productlocale;     }      /**     * add productlocale     *     * @param productlocale $productlocale     */     /*     public function addproductlocale(productlocale $productlocale)     {         $this->productlocales[] = $productlocale;     }      public function removeproductlocale(productlocale $productlocale)     {         $this->productlocale->removeelement($productlocale);     }*/         /**      * productpic      *      * @return \wearplay\wearbundle\entity\productpic      */     public function getproductpic()     {         return $this->productpic;     }      /**      * set productpic      *      * @param \wearplay\wearbundle\entity\productpic $productpic      * @return product      */     public function setproductpic(productpic $productpic = null)     {         $this->productpic = $productpic;     }      /**     * add productpic     *     * @param productpic $productpic     */     public function addproductpic(productpic $productpic)    {        $this->productpic[] = $productpic;    } } 

productlocale entity

<?php  namespace wearplay\wearbundle\entity;  use doctrine\orm\mapping orm;  /** * @orm\entity * @orm\haslifecyclecallbacks * @orm\table(name="product_locale") */  class productlocale {     /**     * @orm\id     * @orm\column(type="integer")     * @orm\generatedvalue(strategy="auto")     */     private $id;      /**       * @orm\manytoone(targetentity="product", cascade="persist")       */     private $product;      /**      *@orm\column(name="market_nation", type="string")      */     private $marketnation;      /**      * @orm\column(type="string")      */     private $link;      /**      * @orm\column(type="decimal", precision=9, scale=2)      */     private $price;      /**      * @orm\column(type="string", length=3)      */     private $currency;      /**      * @orm\column(name="creation_date", type="datetime", nullable=false)      */     private $creationdate;      /**       * @orm\prepersist      */       /*     public function addproduct(product $product)     {         if (!$this->product->contains($product)) {             $this->product->add($product);         }     }     */     public function createtimestamps()     {         $this->creationdate = new \datetime(date('y-m-d h:i:s'));     }       /**      * id      *      * @return integer       */     public function getid()     {         return $this->id;     }      /**      * set marketnation      *      * @param string $marketnation      * @return productlocale      */     public function setmarketnation($marketnation)     {         $this->marketnation = $marketnation;          return $this;     }      /**      * marketnation      *      * @return string       */     public function getmarketnation()     {         return $this->marketnation;     }      /**      * set link      *      * @param string $link      * @return productlocale      */     public function setlink($link)     {         $this->link = $link;          return $this;     }      /**      * link      *      * @return string       */     public function getlink()     {         return $this->link;     }      /**      * set price      *      * @param float $price      * @return productlocale      */     public function setprice($price)     {         $this->price = $price;          return $this;     }      /**      * price      *      * @return float       */     public function getprice()     {         return $this->price;     }      /**      * set currency      *      * @param string $currency      * @return productlocale      */     public function setcurrency($currency)     {         $this->currency = $currency;          return $this;     }      /**      * currency      *      * @return string       */     public function getcurrency()     {         return $this->currency;     }      /**      * set creationdate      *      * @param \datetime $creationdate      * @return productlocale      */     public function setcreationdate($creationdate)     {         $this->creationdate = $creationdate;          return $this;     }      /**      * creationdate      *      * @return \datetime       */     public function getcreationdate()     {         return $this->creationdate;     }      /**      * set product      *      * @param \wearplay\wearbundle\entity\product $product      * @return productlocale      */     public function setproduct(\wearplay\wearbundle\entity\product $product = null)     {         $this->product = $product;          return $this;     }      /**      * product      *      * @return \wearplay\wearbundle\entity\product       */     public function getproduct()     {         return $this->product;     }  } 

solved

yes @ihsan , @snyx, you're absolutely right, removed line: @assert\type(type="wearplay\wearbundle\entity\productlocale , worked perfectly.

i'm sorry trivial question i'm pretty new in symfony2.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -