public function actionDeleteHistory($id) { if (($model = BudgetHistory::findOne($id)) !== null) { try { $model->delete(); return $this->redirect(Url::previous()); } catch (\Exception $e) { $msg = isset($e->errorInfo[2]) ? $e->errorInfo[2] : $e->getMessage(); \Yii::$app->getSession()->setFlash('error', $msg); return $this->redirect(Url::previous()); } } else { throw new HttpException(404, 'The requested page does not exist.'); } }