Example #1
0
 /**
  * function ::create ($data)
  */
 public static function create($data)
 {
     $now = strtotime('now');
     $username = Yii::$app->user->identity->username;
     $model = new BlackItem();
     if ($model->load($data)) {
         if ($log = new UserLog()) {
             $log->username = $username;
             $log->action = "Create";
             $log->object_class = "BlackItem";
             $log->created_at = $now;
             $log->is_success = 0;
             $log->save();
         }
         $model->created_at = $now;
         $model->created_by = $username;
         if ($model->save()) {
             if ($log) {
                 $log->object_pk = $model->id;
                 $log->is_success = 1;
                 $log->save();
             }
             return $model;
         }
         $model->getErrors();
         return $model;
     }
     return false;
 }