/** * Deletes a particular model. * If deletion is successful, the browser will be redirected to the 'admin' page. * @param integer $id the ID of the model to be deleted */ public function actionDelete($id) { if (Yii::app()->request->isPostRequest) { // we only allow deletion via POST request $model = $this->loadModel($id); $img = $model->photo_karyawan; if ($model->delete()) { if (file_exists(Params::urlIconModulDirectory() . $img) && file_exists(Params::urlIconModulThumbsDirectory() . 'kecil_' . $img) && $img != null) { unlink(Params::urlIconModulDirectory() . $img); unlink(Params::urlIconModulThumbsDirectory() . 'kecil_' . $img); } } // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser if (!isset($_GET['ajax'])) { $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin')); } } else { throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.'); } }