/** * 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); $student_info = StudentInfo::model()->findByPk($model->student_transaction_student_id); if ($model->student_transaction_student_address_id != null) { $address = StudentAddress::model()->findByPk($model->student_transaction_student_address_id); } $stud_photo = StudentPhotos::model()->findByPk($model->student_transaction_student_photos_id); if ($model->student_transaction_languages_known_id != null) { $lang_known = LanguagesKnown::model()->findByPk($model->student_transaction_languages_known_id); } $dir1 = Yii::getPathOfAlias('webroot') . '/college_data/stud_images/'; if ($dh = opendir($dir1)) { if ($stud_photo->student_photos_path == "no-images") { } else { if (file_exists($dir1 . $stud_photo->student_photos_path)) { //chmod($dir1.$stud_photo->student_photos_path, 777); unlink($dir1 . $stud_photo->student_photos_path); } } } closedir($dh); if ($this->loadModel($id)->delete()) { $use_model = User::model()->findByPk($model->student_transaction_user_id)->delete(); $stud_photo->delete(); $student_info->delete(); if ($model->student_transaction_student_address_id != null) { $address->delete(); } if ($model->student_transaction_languages_known_id != null) { $lang_known->delete(); } StudentPaidFeesDetails::model()->deleteAll("student_paid_student_id = :studId", array(':studId' => $id)); StudentAcademicRecordTrans::model()->deleteAll("student_academic_record_trans_stud_id = :studId", array(':studId' => $id)); StudentDocsTrans::model()->deleteAll("student_docs_trans_user_id = :studId", array(':studId' => $id)); } 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.'); } }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = StudentPaidFeesDetails::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }