public function actionAdd() { $this->layout = '//layouts/admin'; $this->pageTitle = 'Новый баннер'; $this->breadcrumbs = array('Баннеры' => array('/admin/banners'), 'Новый баннер'); $success = false; if (isset($_POST['data'])) { $model = new Banners(); $dataArray = $_POST['data']; $dataArray['is_active'] = isset($_POST['data']['is_active']) && $_POST['data']['is_active'] == 1 ? 1 : 0; $model->setAttributes($dataArray); if ($model->save()) { $success = true; if (isset($_FILES['img']) && $_FILES['img']['name']) { $uploaddir = 'images/upload/' . date("d.m.Y", time()); if (!is_dir($uploaddir)) { mkdir($uploaddir); } if (isset($_FILES['img'])) { $tmp_name = $_FILES["img"]["tmp_name"]; $name = $_FILES["img"]["name"]; if ($name) { $ext = explode(".", $name); $uploadfile = $uploaddir . '/nc_' . $model->id . '_' . md5(basename($name) . time()) . "." . end($ext); if (move_uploaded_file($tmp_name, $uploadfile)) { $model->setAttributes(array("img" => "/" . $uploadfile)); $model->save(); } } } } } } if ($success) { $this->redirect("/admin/banners"); } if (!isset($model) || !is_object($model)) { $model = new Banners(); } $this->render('add', array("errors" => $model->errors)); }