DEXDEVS / abc-ic

ABC Learning High School
Other
0 stars 1 forks source link

Create Timestamp #4

Closed AnasShafqat closed 5 years ago

AnasShafqat commented 5 years ago

Timestamp is required for the following fileds

  1. created_at
  2. updated_at
  3. created_by
  4. updated_by
Kinza59 commented 5 years ago

Timestamp fields are populating automatically:

in controller.php:

actionCreate() {
$model->created_by = Yii::$app->user->identity->id; 
                $model->created_at = new \yii\db\Expression('NOW()');
                $model->updated_by = '0';
                $model->updated_at = '0'; 
                $model->save();
}
----------------------------------------------------------------------------------------------
actionUpdate(){
$model->updated_by = Yii::$app->user->identity->id;
                $model->updated_at = new \yii\db\Expression('NOW()');
                $model->created_by = $model->created_by;
                $model->created_at = $model->created_at;
                $model->save();
}