Skip to content

Instantly share code, notes, and snippets.

@wpottier
Created March 12, 2014 10:38
Show Gist options
  • Save wpottier/9504481 to your computer and use it in GitHub Desktop.
Save wpottier/9504481 to your computer and use it in GitHub Desktop.
<?php
namespace Mon\Site\BlogBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Class BaseEntity
*
* @ORM\MappedSuperclass
* @ORM\HasLifecycleCallbacks
*/
class BaseEntity
{
/**
* @ORM\Column(type="datetime", name="created_at")
*/
private $createdAt;
/**
* Store the date when this entity was updated for the last time
*
* @ORM\Column(type="datetime", name="updated_at")
*/
private $updatedAt;
/**
* @ORM\PrePersist
*/
public function persist()
{
$this->createdAt = $this->updatedAt = new \DateTime("now");
}
/**
* @ORM\PreUpdate
*/
public function updated()
{
$this->updatedAt = new \DateTime("now");
}
/**
* Set createdAt
*
* @param \DateTime $createdAt
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
}
/**
* Get createdAt
*
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set updatedAt
*
* @param \DateTime $updatedAt
*/
public function setUpdatedAt($updatedAt)
{
$this->updatedAt = $updatedAt;
}
/**
* Get updatedAt
*
* @return \DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment