项目开发中的功能实现与服务管理
一、任务实体的时间跟踪属性添加
在处理任务实体时,跟踪其活动情况十分有用。例如,在仪表板区域实现某些功能时,可能需要获取特定任务的访问时间。为了记录新任务的创建时间和最后更新时间,我们需要定义新的属性。以下是具体代码:
// src/AppBundle/Entity/Task.php
//...
/**
* Task
* …
* @ORM\HasLifecycleCallbacks()
*/
class Task
{
//...
/**
* @var \DateTime
* @ORM\Column(name="created_at", type="datetime")
*/
protected $createdAt;
/**
* @var \DateTime
* @ORM\Column(name="updated_at", type="datetime")
*/
protected $updatedAt;
/**
* Sets the creation date
* @ORM\PrePersist
*/
public function setCreatedAt()
{
$this->createdAt = new \DateTime();
$this->updatedAt = new \DateTime();
}
/**
* Returns the creation date