/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Records(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Records'])) { $model->attributes = $_POST['Records']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->record_id)); } } $this->render('create', array('model' => $model)); }
public function actionFile() { $uploadedFile = CUploadedFile::getInstanceByName("import_file"); if (isset($uploadedFile)) { echo "Configure the date and IP"; $csvFile = fopen($uploadedFile->tempName, "r"); $headers = fgetcsv($csvFile); $isFirstRow = true; while (!feof($csvFile)) { if ($isFirstRow) { $isFirstRow = false; continue; } else { /*get out if empty!*/ $curRow = fgetcsv($csvFile); $curRow = preg_replace("/\r(?!\n)/", '', $curRow); if (empty($curRow)) { continue; } $processData = array_flip($headers); $counter = 0; foreach ($processData as $key => $value) { $processData[$key] = $curRow[$value]; } $processData = array_map('utf8_encode', $processData); $newRecord = new Records("old_file"); $newRecord->account_id = intval($uploadedFile->getName()); $newRecord->claimData = json_encode($processData); $newRecord->ip_address = $curRow[2]; //for now $dt = date_create_from_format("m/d/Y H:i", $curRow[1]); // $newRecord->date_created = $dt->format("Y-m-d H:i:s"); // $newRecord->date_updated = $dt->format("Y-m-d H:i:s"); $newRecord->date_created = $dt->format("Y-m-d H:i:s"); $newRecord->date_updated = $dt->format("Y-m-d H:i:s"); $newRecord->other_information = "none"; if (!$newRecord->save()) { Yii::app()->user->setFlash('error', CHtml::errorSummary($newRecord)); } else { Yii::app()->user->setFlash('success', '<strong>Well done!</strong> Data imported.'); } } } } $this->render("import"); }