protected function createOrUpdate(Event $model) { if (isset($_POST['Event'])) { $model->scenario = 'backend'; $model->attributes = $_POST['Event']; $categories = EventCategory::model()->findAllByPk($_POST['Event']['categories']); $links = array(); if (!$model->isNewRecord) { EventLink::model()->deleteAllByAttributes(array('eventId' => $model->id)); } if (isset($_POST['EventLink'])) { foreach ($_POST['EventLink'] as $i => $info) { $link = new EventLink(); $link->attributes = $info; if (strlen($link->url) > 0) { $links[] = $link; } } } $model->categories = $categories; $model->links = $links; $model->validate(); if ($model->save()) { if ($pictureSmall = CUploadedFile::getInstance($model, 'pictureSmall')) { $model->pictureSmall = $pictureSmall; } if ($pictureBig = CUploadedFile::getInstance($model, 'pictureBig')) { $model->pictureBig = $pictureBig; } $model->setTags($_POST['Event']['tagsString'])->save(); $this->redirect(array('view', 'id' => $model->id)); } } }
/** * 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 the ID of the model to be loaded */ public function loadModel($id) { $model = EventCategory::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }