Skip to content

Instantly share code, notes, and snippets.

@Ocramius
Created October 30, 2011 17:43
Show Gist options
  • Save Ocramius/1326176 to your computer and use it in GitHub Desktop.
Save Ocramius/1326176 to your computer and use it in GitHub Desktop.
[doctrine-user] Auto create date - annoation - Codeigniter 2 and Doctrine 2
<?php
$worker = new models\Workers();
$worker->setEmail($data['email']);
$this->em->persist($worker);
$this->em->flush();
<?php
namespace models;
/**
* @Entity
* @Table(name="workers")
* @HasLifecycleCallback
*/
class Workers {
/**
* @Id
* @Column(type="integer", nullable=false)
* @GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @Column(type="string", length=255, unique=true, nullable=false)
*/
protected $email;
/**
* @var datetime $created_on
*
* @gedmo:Timestampable(on="create")
* @Column(type="datetime")
*/
protected $created_on;
/** @PrePersist */
function onPrePersist()
{
$this->created_on = new \DateTime();
}
/* Setters & Getters */
public function setEmail($email){ $this->email = $email; }
public function getEmail(){ return $this->email; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment