/** * Deletes a particular model. * If deletion is successful, the browser will be redirected to the 'index' page. */ public function actionDelete() { if (Yii::$app->request->isPost) { // we only allow deletion via POST request $model = $this->loadModel(); /** @var Profile $profile */ $profile = Profile::findOne($model->id); // Make sure profile exists if ($profile) { $profile->delete(); } $model->delete(); // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser if (Yii::$app->request->isAjax) { return ''; } return $this->redirect(['/user/admin']); } else { throw new HttpException(400, 'Invalid request. Please do not repeat this request again.'); } }