/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new FileForm(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['FileForm'])) { $file = new File(); $file->name = $_POST['FileForm']['name']; $slug = $file->generateRandomString(); while (true) { $invalidSlug = File::model()->findByAttributes(array('slug' => $slug)); if (!$invalidSlug) { break; } } $file->slug = $slug; if ($file->save()) { $fileFormTypeArray = $file->fileType(); foreach ($fileFormTypeArray as $fileType) { if (trim($_POST['FileForm'][$fileType]) != "") { $url = new Url(); $url->type = $fileType; $url->file_id = $file->id; $url->day_update = date('d'); $url->month_update = date('m'); $url->url = $_POST['FileForm'][$fileType]; $url->save(); } } $statistic = new Statistic(); $statistic->file_id = $file->id; $statistic->date = date('dmY'); $statistic->save(); } $this->redirect(array('admin')); } $this->render('create', array('model' => $model)); }