Jonathon Posted December 20, 2012 Share Posted December 20, 2012 Hello With this code in the book, I placed it in my user model rather than use a scenario. Is that all there is to it when you create a new user. Now it would either create the date_created column or update the date_modified column? I was thrown a little bit by the $this->created and $this->modified statements in the book as they don't directly match the column names' being used in the book. Tried to look into the beforeSave() more but couldn't find anything. /** * Checks whether a record is new or not and updates date_created or _date_updated columns */ public function beforeSave(){ // If new DB record if ($this->isNewRecord) { $this->created = new CDbExpression('TIMESTAMP()'); } else { // If updated record $this->modified = new CDExpression('TIMESTAMP()'); } return parent::beforeSave(); } Thanks Jonathon Link to comment Share on other sites More sharing options...
Ziggi Posted December 20, 2012 Share Posted December 20, 2012 Hmm - so... what is your question actually? I can't see any. Link to comment Share on other sites More sharing options...
Edward Posted December 20, 2012 Share Posted December 20, 2012 Hello With this code in the book, I placed it in my user model rather than use a scenario. Is that all there is to it when you create a new user. Now it would either create the date_created column or update the date_modified column? I was thrown a little bit by the $this->created and $this->modified statements in the book as they don't directly match the column names' being used in the book. Tried to look into the beforeSave() more but couldn't find anything. /** * Checks whether a record is new or not and updates date_created or _date_updated columns */ public function beforeSave(){ // If new DB record if ($this->isNewRecord) { $this->created = new CDbExpression('TIMESTAMP()'); } else { // If updated record $this->modified = new CDExpression('TIMESTAMP()'); } return parent::beforeSave(); } Thanks Jonathon The created and modified words would need to be changed to matching attribute names in your user active record otherwise it wouldn't work. I take it that is example code. 1 Link to comment Share on other sites More sharing options...
Jonathon Posted December 20, 2012 Author Share Posted December 20, 2012 Thanks Edward Yeah that's what I thought, does Yii just map your DB columns to attributes. Yes i've just looked at CActiveRecord -thanks Link to comment Share on other sites More sharing options...
Recommended Posts