/** * This method accepts user's id and an array of data and creates the model. * Returns model if successfully created. * Returns the error validated model if validation fails. * * data array should have the following hash keys- * 1. question * 2. description * 3. category_id * 4. email_answer * * @param array $data,string $userId * @return model || model with errors */ public static function addJukeboxQuestion($userId, $data) { $jukeboxQuestions = new JukeboxQuestions(); $jukeboxQuestions->user_id = $userId; $jukeboxQuestions->attributes = $data; $jukeboxQuestions->save(); return $jukeboxQuestions; }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new JukeboxQuestions(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['JukeboxQuestions'])) { $model->attributes = $_POST['JukeboxQuestions']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }