Jonathon 255 Posted December 20, 2012 Report 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 Quote Link to post Share on other sites
Ziggi 5 Posted December 20, 2012 Report Share Posted December 20, 2012 Hmm - so... what is your question actually? I can't see any. Quote Link to post Share on other sites
Edward 108 Posted December 20, 2012 Report 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 Quote Link to post Share on other sites
Jonathon 255 Posted December 20, 2012 Author Report 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 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.