douhuang1852
2015-06-12 08:29
浏览 92
已采纳

Symfony2 Doctrine:ContextErrorException:Catchable Fatal Error:类DateTime的对象无法转换为字符串

In my Symfony2 project I have the following query in my ProductRepository.php:

$dateNow = new \DateTime();
$query = $this->createQueryBuilder('p')
            ->update('MyBundle\Products', 'p')
            ->set('p.published', $dateNow)
            ->getQuery();

$query->execute();

ProductEntity.php:

 /**
     * Set published
     *
     * @param \DateTime $published
     * @return Product
     */
    public function setPublished($published)
    {
        $this->published = $published;

        return $this;
    }

ERROR:

ContextErrorException: Catchable Fatal Error: Object of class DateTime could not be converted to string

In other posts I already read something about toString methods that need to be integrated, but I don't know where to implement it...

图片转代码服务由CSDN问答提供 功能建议

在我的Symfony2项目中,我在 ProductRepository.php 中有以下查询:

  $ dateNow = new \ DateTime(); 
 $ query = $ this-> createQueryBuilder('p')
  - > update('MyBundle \ Products',  'p')
  - > set('p.published',$ dateNow)
  - > getQuery(); 
 
 $ query-> execute(); 
   
 
 

ProductEntity.php:

  / ** 
 *设置已发布
 * 
 * @param  \ DateTime $ published 
 * @return Product 
 * / 
 public function setPublished($ published)
 {
 $ this-> published = $ published; 
 
 return $ this; 
} \  n   
 
 

错误:

  ContextErrorException:Catchable Fatal Error:类DateTime的对象无法转换为字符串
    
 
 

在其他帖子中,我已经阅读了一些有关需要集成的toString方法的内容,但我不知道在哪里实现它...... < / p>

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题