symfony - Symfony2: Object of class DateTime could not be converted to string -


i got error when updating product: (updating category ok)

catchable fatal error: object of class datetime not converted string in c:\xampp\htdocs\phpproject1\vendor\symfony\symfony\src\symfony\component\translation\translator.php line 188

enter image description here

enter image description here

full stack trace:

stack trace in c:\xampp\htdocs\phpproject1\vendor\symfony\symfony\src\symfony\component\translation\translator.php @ line 188   -             $this->loadcatalogue($locale);         }         return strtr($this->catalogues[$locale]->get((string) $id, $domain), $parameters);     }     /** @ errorhandler ->handle ('4096', 'object of class datetime not converted string', 'c:\xampp\htdocs\phpproject1\vendor\symfony\symfony\src\symfony\component\translation\translator.php', '188', array('id' => 'this value should blank.', 'parameters' => array('{{ value }}' => object(datetime)), 'domain' => 'validators', 'locale' => 'en'))  @ strtr ('this value should blank.', array('{{ value }}' => object(datetime)))  in c:\xampp\htdocs\phpproject1\vendor\symfony\symfony\src\symfony\component\translation\translator.php @ line 188   +  @ translator ->trans ('this value should blank.', array('{{ value }}' => object(datetime)), 'validators')  in c:\xampp\htdocs\phpproject1\vendor\symfony\symfony\src\symfony\component\validator\executioncontext.php @ line 93   +  @ executioncontext ->addviolation ('this value should blank.', array('{{ value }}' => object(datetime)))  in c:\xampp\htdocs\phpproject1\vendor\symfony\symfony\src\symfony\component\validator\constraints\blankvalidator.php @ line 30   +  @ blankvalidator ->validate (object(datetime), object(blank))  in c:\xampp\htdocs\phpproject1\vendor\symfony\symfony\src\symfony\component\validator\executioncontext.php @ line 276   +  @ executioncontext ->executeconstraintvalidators (object(datetime), array(object(blank)))  in c:\xampp\htdocs\phpproject1\vendor\symfony\symfony\src\symfony\component\validator\executioncontext.php @ line 241   +  @ executioncontext ->validatevalue (object(datetime), array(object(blank)))  in c:\xampp\htdocs\phpproject1\vendor\symfony\symfony\src\symfony\component\validator\validationvisitor.php @ line 110   +  @ validationvisitor ->visit (object(propertymetadata), object(datetime), 'default', 'data.created_at')  in c:\xampp\htdocs\phpproject1\vendor\symfony\symfony\src\symfony\component\validator\mapping\membermetadata.php @ line 47   +  @ membermetadata ->accept (object(validationvisitor), object(datetime), 'default', 'data.created_at', null)  in c:\xampp\htdocs\phpproject1\vendor\symfony\symfony\src\symfony\component\validator\mapping\classmetadata.php @ line 114   +  @ classmetadata ->accept (object(validationvisitor), object(product), 'default', 'data')  in c:\xampp\htdocs\phpproject1\vendor\symfony\symfony\src\symfony\component\validator\validationvisitor.php @ line 162   +  @ validationvisitor ->validate (object(product), 'default', 'data', true, false)  in c:\xampp\htdocs\phpproject1\vendor\symfony\symfony\src\symfony\component\validator\executioncontext.php @ line 227   +  @ executioncontext ->validate (object(product), 'data', 'default', true)  in c:\xampp\htdocs\phpproject1\vendor\symfony\symfony\src\symfony\component\form\extension\validator\constraints\formvalidator.php @ line 60   +  @ formvalidator ->validate (object(form), object(form))  in c:\xampp\htdocs\phpproject1\vendor\symfony\symfony\src\symfony\component\validator\executioncontext.php @ line 276   +  @ executioncontext ->executeconstraintvalidators (object(form), array(object(form)))  in c:\xampp\htdocs\phpproject1\vendor\symfony\symfony\src\symfony\component\validator\executioncontext.php @ line 241   +  @ executioncontext ->validatevalue (object(form), array(object(form)))  in c:\xampp\htdocs\phpproject1\vendor\symfony\symfony\src\symfony\component\validator\validationvisitor.php @ line 110   +  @ validationvisitor ->visit (object(classmetadata), object(form), 'default', '')  in c:\xampp\htdocs\phpproject1\vendor\symfony\symfony\src\symfony\component\validator\mapping\classmetadata.php @ line 107   +  @ classmetadata ->accept (object(validationvisitor), object(form), 'default', '')  in c:\xampp\htdocs\phpproject1\vendor\symfony\symfony\src\symfony\component\validator\validationvisitor.php @ line 162   +  @ validationvisitor ->validate (object(form), 'default', '', false, false)  in c:\xampp\htdocs\phpproject1\vendor\symfony\symfony\src\symfony\component\validator\validator.php @ line 90   +  @ validator ->validate (object(form))  in c:\xampp\htdocs\phpproject1\vendor\symfony\symfony\src\symfony\component\form\extension\validator\eventlistener\validationlistener.php @ line 55   +  @ validationlistener ->validateform (object(formevent))  @ call_user_func (array(object(validationlistener), 'validateform'), object(formevent))  in c:\xampp\htdocs\phpproject1\app\cache\dev\classes.php @ line 1655   +  @ eventdispatcher ->dodispatch (array(array(object(validationlistener), 'validateform')), 'form.post_bind', object(formevent))  in c:\xampp\htdocs\phpproject1\app\cache\dev\classes.php @ line 1588   +  @ eventdispatcher ->dispatch ('form.post_bind', object(formevent))  in c:\xampp\htdocs\phpproject1\vendor\symfony\symfony\src\symfony\component\eventdispatcher\immutableeventdispatcher.php @ line 42   +  @ immutableeventdispatcher ->dispatch ('form.post_bind', object(formevent))  in c:\xampp\htdocs\phpproject1\vendor\symfony\symfony\src\symfony\component\form\form.php @ line 624   +  @ form ->submit (object(request))  in c:\xampp\htdocs\phpproject1\vendor\symfony\symfony\src\symfony\component\form\form.php @ line 638   +  @ form ->bind (object(request))  in c:\xampp\htdocs\phpproject1\src\mobile\businessbundle\controller\productcontroller.php @ line 132   +  @ productcontroller ->updateaction (object(request), '7')  @ call_user_func_array (array(object(productcontroller), 'updateaction'), array(object(request), '7'))  in c:\xampp\htdocs\phpproject1\app\bootstrap.php.cache @ line 2770   +  @ httpkernel ->handleraw (object(request), '1')  in c:\xampp\htdocs\phpproject1\app\bootstrap.php.cache @ line 2744   +  @ httpkernel ->handle (object(request), '1', true)  in c:\xampp\htdocs\phpproject1\app\bootstrap.php.cache @ line 2874   +  @ containerawarehttpkernel ->handle (object(request), '1', true)  in c:\xampp\htdocs\phpproject1\app\bootstrap.php.cache @ line 2175   +  @ kernel ->handle (object(request))  in c:\xampp\htdocs\phpproject1\web\app_dev.php @ line 29   +  

here code: product.php

<?php  namespace mobile\businessbundle\entity;  use doctrine\orm\mapping orm; use lib\functions;  /** * product */ class product {  /**  * @var integer  */ private $id;  /**  * @var string  */ private $name;  /**  * @var string  */ private $slug;  /**  * @var float  */ private $price;  /**  * @var float  */ private $discount;  /**  * @var string  */ private $description;  /**  * @var string  */ private $detail;  /**  * @var string  */ private $sku;  /**  * @var integer  */ private $views;  /**  * @var boolean  */ private $is_active;  /**  * @var \datetime  */ private $created_at;  /**  * @var \datetime  */ private $updated_at;  /**  * @var \doctrine\common\collections\collection  */ private $categories;  /**  * constructor  */ public function __construct() {     $this->categories = new \doctrine\common\collections\arraycollection(); }  /**  * 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; }  /**  * set slug  *  * @param string $slug  * @return product  */ public function setslug($slug) {     $this->slug = $slug;      return $this; }  /**  * slug  *  * @return string   */ public function getslug() {     return $this->slug; }  /**  * set price  *  * @param float $price  * @return product  */ public function setprice($price) {     $this->price = $price;      return $this; }  /**  * price  *  * @return float   */ public function getprice() {     return $this->price; }  /**  * set discount  *  * @param float $discount  * @return product  */ public function setdiscount($discount) {     $this->discount = $discount;      return $this; }  /**  * discount  *  * @return float   */ public function getdiscount() {     return $this->discount; }  /**  * set description  *  * @param string $description  * @return product  */ public function setdescription($description) {     $this->description = $description;      return $this; }  /**  * description  *  * @return string   */ public function getdescription() {     return $this->description; }  /**  * set detail  *  * @param string $detail  * @return product  */ public function setdetail($detail) {     $this->detail = $detail;      return $this; }  /**  * detail  *  * @return string   */ public function getdetail() {     return $this->detail; }  /**  * set sku  *  * @param string $sku  * @return product  */ public function setsku($sku) {     $this->sku = $sku;      return $this; }  /**  * sku  *  * @return string   */ public function getsku() {     return $this->sku; }  /**  * set views  *  * @param integer $views  * @return product  */ public function setviews($views) {     $this->views = $views;      return $this; }  /**  * views  *  * @return integer   */ public function getviews() {     return $this->views; }  /**  * set is_active  *  * @param boolean $isactive  * @return product  */ public function setisactive($isactive) {     $this->is_active = $isactive;      return $this; }  /**  * is_active  *  * @return boolean   */ public function getisactive() {     return $this->is_active; }  /**  * set created_at  *  * @param \datetime $createdat  * @return product  */ public function setcreatedat($createdat) {     $this->created_at = $createdat;      return $this; }  /**  * created_at  *  * @return \datetime   */ public function getcreatedat() {     return $this->created_at; }  /**  * set updated_at  *  * @param \datetime $updatedat  * @return product  */ public function setupdatedat($updatedat) {     $this->updated_at = $updatedat;      return $this; }  /**  * updated_at  *  * @return \datetime   */ public function getupdatedat() {     return $this->updated_at; }  /**  * add categories  *  * @param \mobile\businessbundle\entity\category $categories  * @return product  */ public function addcategorie(\mobile\businessbundle\entity\category $categories) {     $this->categories[] = $categories;      return $this; }  /**  * remove categories  *  * @param \mobile\businessbundle\entity\category $categories  */ public function removecategorie(\mobile\businessbundle\entity\category $categories) {     $this->categories->removeelement($categories); }  /**  * categories  *  * @return \doctrine\common\collections\collection   */ public function getcategories() {     return $this->categories; } /**  * @orm\prepersist  */ public function onprepersist() {     $this->created_at = new \datetime();     $this->updated_at = new \datetime();     $this->views = 0;     $this->is_active = true;     $this->slug = functions::url_friendly($this->name); }  /**  * @orm\preupdate  */ public function onpreupdate() {     $this->updated_at = new \datetime(); }  public function __tostring() {     return $this->name; } } 

product.orm.yml

mobile\businessbundle\entity\product: type: entity repositoryclass: mobile\businessbundle\entity\productrepository manytomany:     categories:         targetentity: category         inversedby: products table: products fields:     id:         type: bigint         id: true         generator:             strategy: auto     name:         type: string         length: 255     slug:         type: string         length: 255     price:         type: decimal         length: null     discount:         type: decimal         length: null     description:         type: text         length: null     detail:         type: text         length: null     sku:         type: string         length: 45     views:         type: bigint     is_active:         type: boolean     created_at:         type: datetime     updated_at:         type: datetime lifecyclecallbacks:   prepersist: [onprepersist]   preupdate: [onpreupdate] 

producttype.php

<?php  namespace mobile\businessbundle\form;  use symfony\component\form\abstracttype; use symfony\component\form\formbuilderinterface; use symfony\component\optionsresolver\optionsresolverinterface;  class producttype extends abstracttype { public function buildform(formbuilderinterface $builder, array $options) {     $builder         ->add('name')         ->add('slug')         ->add('price')         ->add('discount')         ->add('description')         ->add('detail')         ->add('sku')         ->add('views')         ->add('is_active')         ->add('created_at')         ->add('updated_at')         ->add('categories')     ; }  public function setdefaultoptions(optionsresolverinterface $resolver) {     $resolver->setdefaults(array(         'data_class' => 'mobile\businessbundle\entity\product'     )); }  public function getname() {     return 'mobile_businessbundle_producttype'; } } 

productcontroller.php

<?php  namespace mobile\businessbundle\controller;  use symfony\component\httpfoundation\request; use symfony\bundle\frameworkbundle\controller\controller;  use mobile\businessbundle\entity\product; use mobile\businessbundle\form\producttype;  /**  * product controller.  *  */ class productcontroller extends controller {  /**  * lists product entities.  *  */ public function indexaction() {     $em = $this->getdoctrine()->getmanager();      $entities = $em->getrepository('mobilebusinessbundle:product')->findall();      return $this->render('mobilebusinessbundle:product:index.html.twig', array(         'entities' => $entities,     )); } /**  * creates new product entity.  *  */ public function createaction(request $request) {     $entity  = new product();     $form = $this->createform(new producttype(), $entity);     $form->bind($request);      if ($form->isvalid()) {         $em = $this->getdoctrine()->getmanager();         $em->persist($entity);         $em->flush();          return $this->redirect($this->generateurl('product_show', array('id' => $entity->getid())));     }      return $this->render('mobilebusinessbundle:product:new.html.twig', array(         'entity' => $entity,         'form'   => $form->createview(),     )); }  /**  * displays form create new product entity.  *  */ public function newaction() {     $entity = new product();     $form   = $this->createform(new producttype(), $entity);      return $this->render('mobilebusinessbundle:product:new.html.twig', array(         'entity' => $entity,         'form'   => $form->createview(),     )); }  /**  * finds , displays product entity.  *  */ public function showaction($id) {     $em = $this->getdoctrine()->getmanager();      $entity = $em->getrepository('mobilebusinessbundle:product')->find($id);      if (!$entity) {         throw $this->createnotfoundexception('unable find product entity.');     }      $deleteform = $this->createdeleteform($id);      return $this->render('mobilebusinessbundle:product:show.html.twig', array(         'entity'      => $entity,         'delete_form' => $deleteform->createview(),        )); }  /**  * displays form edit existing product entity.  *  */ public function editaction($id) {     $em = $this->getdoctrine()->getmanager();      $entity = $em->getrepository('mobilebusinessbundle:product')->find($id);      if (!$entity) {         throw $this->createnotfoundexception('unable find product entity.');     }      $editform = $this->createform(new producttype(), $entity);     $deleteform = $this->createdeleteform($id);      return $this->render('mobilebusinessbundle:product:edit.html.twig', array(         'entity'      => $entity,         'edit_form'   => $editform->createview(),         'delete_form' => $deleteform->createview(),     )); }  /**  * edits existing product entity.  *  */ public function updateaction(request $request, $id) {     $em = $this->getdoctrine()->getmanager();      $entity = $em->getrepository('mobilebusinessbundle:product')->find($id);      if (!$entity) {         throw $this->createnotfoundexception('unable find product entity.');     }      $deleteform = $this->createdeleteform($id);     $editform = $this->createform(new producttype(), $entity);     $editform->bind($request);      if ($editform->isvalid()) {         $em->persist($entity);         $em->flush();          return $this->redirect($this->generateurl('product_edit', array('id' => $id)));     }      return $this->render('mobilebusinessbundle:product:edit.html.twig', array(         'entity'      => $entity,         'edit_form'   => $editform->createview(),         'delete_form' => $deleteform->createview(),     )); } /**  * deletes product entity.  *  */ public function deleteaction(request $request, $id) {     $form = $this->createdeleteform($id);     $form->bind($request);      if ($form->isvalid()) {         $em = $this->getdoctrine()->getmanager();         $entity = $em->getrepository('mobilebusinessbundle:product')->find($id);          if (!$entity) {             throw $this->createnotfoundexception('unable find product entity.');         }          $em->remove($entity);         $em->flush();     }      return $this->redirect($this->generateurl('product')); }  /**  * creates form delete product entity id.  *  * @param mixed $id entity id  *  * @return \symfony\component\form\form form  */ private function createdeleteform($id) {     return $this->createformbuilder(array('id' => $id))         ->add('id', 'hidden')         ->getform()     ; } } 

edit.html.twig

{% extends '::base.html.twig' %}  {% block body -%}     <h1>product edit</h1>      <form action="{{ path('product_update', { 'id': entity.id }) }}" method="post" {{ form_enctype(edit_form) }}>         <input type="hidden" name="_method" value="put" />         {{ form_widget(edit_form) }}         <p>             <button type="submit">edit</button>         </p>     </form>          <ul class="record_actions">     <li>         <a href="{{ path('product') }}">             list         </a>     </li>     <li>         <form action="{{ path('product_delete', { 'id': entity.id }) }}" method="post">             <input type="hidden" name="_method" value="delete" />             {{ form_widget(delete_form) }}             <button type="submit">delete</button>         </form>     </li> </ul> {% endblock %} 

updated: error occurred because created file validation.yml product entity created_at : blank. mobile\businessbundle\entity\product: properties: created_at: - blank: ~

looks problems in validators. possible validators.yml cause dont see validation annotations on entity. trying validate datetime notblank validator trying show error. change notnull validator.

'c:\xampp\htdocs\phpproject1\vendor\symfony\symfony\src\symfony\component\translation\translator.php', '188', array('id' => 'this value should blank.', 'parameters' => array('{{ value }}' => object(datetime)), 'domain' => 'validators', 'locale' => 'en'))  @ strtr ('this value should blank.', array('{{ value }}' => object(datetime)))  

Comments