Insert Owner, Time Etc

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.

Thanks!

hi you can make use of AR hooks to automatically populate this stuff

  1. add columns in your table (create_at, owner/user)

  2. 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

Thank`s it works B) yii, is awesome, I like it

glad i could help yes Yii is awesome

;) What about access levels on site? In yii is defined admin, login user and guest,

from my db, I need defined levels like 0-3, where 0 = guest, 1 = moder, 2 = admin.

And change page view if not logged show only login form without page content, like social engines.

Thanks.

Dear Friend

We can make the permissions finely granular.

By appropriate accessRules in a Controller, you can acheive what you desire.

To set the rules kindly go through the following.

CAccessControllerFilter.

Regards.

Hi loud there is very detailed article on wiki written by Antonio please do take a look

http://www.yiiframework.com/wiki/191/implementing-a-user-level-access-system/