/** * 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 $id the ID of the model to be loaded * @return FuelCost the loaded model * @throws CHttpException */ public function loadModel($id) { $model=FuelCost::model()->findByPk($id); if($model===null) throw new CHttpException(404,'The requested page does not exist.'); return $model; }
/** * 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()->user->checkAccess('admin')){ $fuel = $this->loadModel($id); FuelCost::model()->find(array('condition' => 'fuel_id='.$fuel->id))->delete(); $fuel->delete(); // 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 { $this->redirect('/admin/user/login'); } }