Jump to content
Larry Ullman's Book Forums

User Models And Admin Use Of Them


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 post
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 post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...