예제 #1
0
파일: Api.php 프로젝트: sangkil/application
 /**
  * Process output. Throw error when not success with unknown reason.
  * @param boolean      $success
  * @param ActiveRecord $model
  *
  * @return ActiveRecord
  * @throws \yii\web\ServerErrorHttpException
  */
 protected static function processOutput($success, $model)
 {
     if (!$success && !$model->hasErrors()) {
         throw new ServerErrorHttpException('Error with unknown reason.');
     }
     return $model;
 }
예제 #2
0
 /**
  * Run Create/Read/Update/Delete action
  *
  * Set error flash and throw Exception, if action failed
  * Return nothing if action succeed
  *
  * @param \yii\db\ActiveRecord|\yii\db\ActiveRecord[] $model
  * @return void
  * @throws \Exception
  */
 protected function runCrudAction($model)
 {
     if ($model instanceof Model) {
         if (!call_user_func([$model, $this->modelAction])) {
             if ($model->hasErrors()) {
                 $this->flashError = [];
                 foreach ($model->getErrors() as $errors) {
                     $this->flashError = array_merge($this->flashError, $errors);
                 }
             }
             throw new \Exception($this->flashError ? VarDumper::dumpAsString($this->flashError) : 'Unknown error');
         }
         return;
     }
     foreach ($model as $concreteModel) {
         $this->runCrudAction($concreteModel);
     }
 }