Jump to content
Larry Ullman's Book Forums

User Models And Admin Use Of Them


Jonathon
 Share

Recommended Posts

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

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.

  • Upvote 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...