public function actionProcess() { $model = new PolicyDetails(); if (isset($_POST['PolicyDetails'])) { $policy = Policy::model()->findByPk($_POST['PolicyDetails']['policy']); $policy->policy_number = uniqid(); $policy->amount_paid = $policy->policy_premium; $policy->is_purchased = 'p'; $policy->policy_purchase_date = date("Y-m-d"); $policy->policy_start_date = date("Y-m-d"); $user = User::model()->findByPk(Yii::app()->user->id); $user->credit = $user->credit - $policy->policy_premium; $user->save(); $policy->save(); $model->attributes = $_POST['PolicyDetails']; if ($model->save()) { $this->redirect(array("success")); } } }
/** * 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 Policy the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Policy::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }