Skip to content

Instantly share code, notes, and snippets.

@e-vural
Last active October 7, 2015 14:51
Show Gist options
  • Save e-vural/35ff1806f29b50464942 to your computer and use it in GitHub Desktop.
Save e-vural/35ff1806f29b50464942 to your computer and use it in GitHub Desktop.
namespace Acme\ProjectBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\HasLifecycleCallbacks
* @ORM\Table(name="projects")
*/
class Projects
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string")
*/
protected $name;
/**
* @ORM\Column(type="datetime")
*/
protected $created_at;
/**
* @ORM\Column(type="datetime")
*/
protected $modified_at;
/**
* Now we tell doctrine that before we persist or update we call the updatedTimestamps() function.
*
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public function updatedTimestamps()
{
$this->setModifiedAt(new \DateTime(date('Y-m-d H:i:s')));
if($this->getCreatedAt() == null)
{
$this->setCreatedAt(new \DateTime(date('Y-m-d H:i:s')));
}
}
}
NOTE: @ORM\HasLifecycleCallbacks must be
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment