/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new AdminRadioModel(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['AdminRadioModel'])) { $model->attributes = $_POST['AdminRadioModel']; if (isset($_POST['AdminRadioModel']['time_point'])) { $time_point = implode(',', $_POST['AdminRadioModel']['time_point']); $model->setAttribute('time_point', $time_point); } else { $model->setAttribute('time_point', 1); } if (isset($_POST['AdminRadioModel']['day_week'])) { $day_week = implode(',', $_POST['AdminRadioModel']['day_week']); $model->setAttribute('day_week', $day_week); } else { $model->setAttribute('day_week', 1); } if (isset($_POST['AdminRadioModel']['daytotime'])) { $dayToTime = json_encode($_POST['AdminRadioModel']['daytotime']); $model->setAttribute('day_to_time', $dayToTime); } else { $model->setAttribute('day_to_time', ''); } $model->setAttribute('created_time', date('Y-m-d H:i:s')); if ($model->save()) { if (isset($_POST['AdminRadioModel']['weather_id'])) { $radioWModel = new AdminRadioWeatherModel(); $sql = "INSERT INTO radio_weather(radio_id, weather_id) VALUES"; foreach ($_POST['AdminRadioModel']['weather_id'] as $w) { $radioId = $model->id; $sqlArr[] = "('{$radioId}','{$w}')"; } $sql .= implode(',', $sqlArr); $sql .= "ON DUPLICATE KEY UPDATE radio_id = '{$radioId}'"; //echo '<pre>';print_r($sqlArr);exit; $res = Yii::app()->db->createCommand($sql)->execute(); } if (isset($_POST['tmp_file_path']) && $_POST['tmp_file_path'] != '') { $tmpFile = _APP_PATH_ . DS . "data" . DS . "tmp" . DS . $_POST['tmp_file_path']; if (file_exists($tmpFile)) { //$this->moveFile($model->id, $model->type, $tmpFile); AvatarHelper::processAvatar($model, $tmpFile); } } if (isset($_POST['yt0']) && ($_POST['yt0'] = 'Create')) { $this->redirect(array('view', 'id' => $model->id)); } else { $this->redirect(array('update', 'id' => $model->id)); } } } $this->render('create', array('model' => $model)); }