/** * 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 ParamValue the loaded model * @throws CHttpException */ public function loadModel($id) { $model = ParamValue::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function actionBlank($id) { $event = Event::model()->findByPk($id); if (Yii::app()->request->isAjaxRequest) { $data = Yii::app()->request->getParam('data'); $reg = new Reg(); $reg->user_id = Yii::app()->user->getId(); $reg->event_id = $event->id; try { if (!$reg->save()) { throw new CHttpException(500, 'Internal server error.'); } foreach ($data as $key => $value) { $param_value = new ParamValue(); $param_value->param_id = $value["id"]; $param_value->reg_id = $reg->id; $param_value->value = $value["value"]; if (!$param_value->save()) { // @todo Откат всех инсертов. throw new CHttpException(500, 'Internal server error.'); } } echo CJSON::encode(array('code' => 200)); Yii::app()->end(); } catch (CDbException $error) { throw new CHttpException(400, 'You are already registered for this event.'); } } $reg = Reg::model()->findByAttributes(array('user_id' => Yii::app()->user->getId(), 'event_id' => $id)); if ($reg !== null) { $this->redirect(array('user/blank', 'userId' => Yii::app()->user->getId(), 'eventId' => $id)); Yii::app()->end(); } $this->render('blank', array('event' => $event)); }