注意:类DateTime的对象无法转换为int Symfony2

时间:2016-01-27 04:22:15

标签: symfony datetime doctrine-orm

我希望在创建操作期间获得并节省两次总时数

YAML

    timein:
        type: time
    timeout:
        type: time
        nullable: true
    total:
        type: time
        nullable: true

实体

 private $timein;//DateTime
 private $timeout;//DateTime
 private $total;//DateTime

 /**
 * Get total
 *
 * @return \DateTime
 */
public function getTotal()
{
    return $this->total;
}

/**
 * Set total
 *
 * @param \DateTime $total
 *
 * @return Timerecord
 */
public function setTotal($total)
{
    $this->total = $total;

    return $this;
}

public function getWorkedHoursTimeinTimeout()
{


  if (!empty($this->timein) && !empty($this->timeout)) {
        //if already timed in and timed out, calculate hours from timein to timeout
        $start = $this->timein;
        $end = $this->timeout;
        $start1 = $start;
        $end1 = $end;
        $total_hours = round(($end1-$start1) / 3600);//option1 

    return  $total_hours;



    } /*else {
        $this->total = "";
    }*/

}

现在在控制器内部,我想像这样保存timeim和timeout的总小时数

 $entity->setTotal($entity->getWorkedHoursTimeinTimeout());
        $em->persist($entity);
        $em->flush();

但是我收到了这个错误

  

注意:类DateTime的对象无法转换为int

1 个答案:

答案 0 :(得分:0)

body{ background-color: #DD3735; padding-top:30px; } .slider-wrap{ width:616px; height:120px; border:1px solid #ccc; margin:0 auto; box-shadow: 0 0 10px #000; border-radius:5px; } img, .slider-boxes{ width:120px; height:120px; } .slider-boxes{ display: inline-block; -webkit-transition: all .2s ease-in-out; transition: all .2s ease-in-out; } .slider-boxes:hover{ -webkit-transform: scale(1.30); transform: scale(1.30); box-shadow: 0 0 10px #000; }<div class="slider-wrap"> <div class="slider-boxes"><img src="https://pbs.twimg.com/profile_images/378800000108340114/a586d7a8df39836a114651aef74cd2d0_400x400.jpeg" alt="Image1"></div> <div class="slider-boxes"><img src="https://s-media-cache-ak0.pinimg.com/736x/77/06/4e/77064e4e9ccc289ee5394dd7dbf48011.jpg" alt="Image2"></div> <div class="slider-boxes"><img src="http://gloimg.gearbest.com/gb/2014/201411/goods-img/1415993980392-P-2179386.jpg" alt="Image3"></div> <div class="slider-boxes"><img src="https://pbs.twimg.com/profile_images/378800000451012500/4628fbb9dc70514d389ed9491243866f_400x400.png" alt="Image4"></div> <div class="slider-boxes"><img src="http://howtodrawdat.com/wp-content/uploads/2014/01/1st-pic-Dave-Minion-from-despicable-me.png" alt="Image5"></div> </div>,您尝试保存Total。将实体中DateTime Object的类型更改为DateInterval Object