Last active
October 7, 2015 14:51
-
-
Save e-vural/35ff1806f29b50464942 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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