Permalink
Browse files

added beforeSave() to set created_at and updated_at accordingly

  • Loading branch information...
knut committed Aug 16, 2011
1 parent 2cb00b6 commit 433d238011e181c3048d85f83ed7e8858c421bcf
Showing with 12 additions and 0 deletions.
  1. +12 −0 src/protected/models/Post.php
@@ -114,6 +114,18 @@ public function getBodyHtml() {
return $html;
}
+ protected function beforeSave() {
+ if(parent::beforeSave()) {
+ $now = date('Y-m-d H:i:s');
+ if($this->isNewRecord) {
+ $this->created_at = $now;
+ }
+ $this->updated_at = $now;
+ return true;
+ }
+ return false;
+ }
+
/*public function attributeLabels()
{
return array(

0 comments on commit 433d238

Please sign in to comment.