/** * 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); } }