/**
  * 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 BetOptionUser the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = BetOptionUser::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 /**
  * Handle bet placing (AJAX).
  */
 public function actionDeleteBet()
 {
     //if (!YII_DEBUG && !Yii::app()->request->isAjaxRequest) {
     //    throw new CHttpException('403', 'Forbidden access.');
     //}
     header('Content-Type: application/json;charset=UTF-8');
     if (isset($_POST['bet_id'])) {
         $bet_id = $_POST['bet_id'];
     } else {
         echo json_encode(array('success' => false, 'message' => 'Invalid request'));
         Yii::app()->end();
     }
     //$bet_option_id, $points
     $bet = BetOptionUser::model()->findByPk($bet_id);
     $user = User::model()->findByPk(Yii::app()->user->id);
     if ($bet == NULL || $user == NULL) {
         echo json_encode(array('success' => false, 'message' => 'Bet or user not found', 'data' => NULL));
     } else {
         try {
             $bet_option = $bet->betOption;
             $user->deleteBet($bet);
             echo json_encode(array('success' => true, 'message' => 'Bet deleted successfully', 'data' => array('bet_id' => $bet_option->id, 'user_points' => $user->points)));
         } catch (Exception $ex) {
             echo json_encode(array('success' => false, 'message' => $ex->getMessage(), 'data' => NULL));
         }
     }
     Yii::app()->end();
 }