/** * Updates an existing EventPost model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $event = Event::findOne($model->event_id); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['index']); } else { return $this->render('update', ['model' => $model, 'event' => $event]); } }
public function actionGetEventDetail() { $event = Event::findOne(Yii::$app->request->post('id')); if ($event) { return json_encode(['success' => true, 'data' => ['user' => $event->user->attributes, 'location' => $event->location, 'title' => $event->title, 'start_date' => $event->start_date, 'end_date' => $event->end_date, 'url' => $event->url, 'notes' => $event->notes, 'image' => $event->image, 'region' => $event->region->name, 'genre' => $event->genre->name]]); } else { return json_encode(['success' => false, 'data' => 'Event not found.']); } }
/** * Finds the Event model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Event the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Event::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }