zend framework2 + doctrine 2,为表添加时间

时间:2014-07-14 08:04:34

标签: php zend-framework doctrine-orm doctrine

我需要帮助。所以,我想添加时间类型的行。我有以下代码。 实体maper xml:

<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping>
    <entity name="Entity\Facility" table="facility">
        <id name="_id" column="id" type="integer">
            <generator strategy="AUTO" />
        </id>
        <field name="_time_open" column="time_open" type="time"/>
        <field name="_time_close" column="time_close" type="time"/>

    </entity>
</doctrine-mapping>

这是我的班级:

class Facility extends AbstractEntity {
    private $_time_open;
    private $_time_close;

    public function setTimeOpen($timeOpen) {
        $this->_time_open = $timeOpen;
        return $this;
    }
    public function setTimeClose($timeClose) {
        $this->_time_close = $timeClose;
        return $this;
    }

    public function  getTimeOpen() {
        return $this->_time_open;
    }
    public function  getTimeClose() {
        return $this->_time_close;
    }

}

如何添加时间类型的行? 我试着用这种方式:

$facility->setTimeOpen(new DataTime()->format('h:i:s');

1 个答案:

答案 0 :(得分:0)

所以,就像评论一样。请尝试设置DataTime对象,例如:

$facility->setTimeOpen(new DataTime());

更多doc