Hello, I create blog list with my old db, I have blogcontroller, model blogs and view blogs, that all is ok, and, create new blog I can too only without blogdate and set owner, how can I add blog create time like time(), and blogowner?, who add blog now.
hi you can make use of AR hooks to automatically populate this stuff
add columns in your table (create_at, owner/user)
add a method beforeSave() in your model
public function beforeSave() {
if($this->isNewRecord) {
$this->created_at = date('Y-m-d');
$this->owner = Yii::app()->user; // your currently logged in user who is creating this post
}
return parent::beforeSave();
}
this should do it
EDIT:
added the if statement to check only add it when new record is being generated