public function actionClubsLoad($filename) { if (!is_readable($filename)) { die("Файл '{$filename}' не читается\n"); } else { $strings = preg_split("/\n/", file_get_contents($filename)); echo "Всего строк " . count($strings) . "\n"; $current_city = "Default"; foreach ($strings as $line) { if (strlen($line) > 0) { if ($line[0] === '#') { $current_city = trim(preg_replace('/# /', '', $line)); } else { $club = preg_split('/:/', $line); if (count($club) == 2) { $boss = trim($club[1]); $name = trim($club[0]); $c = new Club(); $c->city = $current_city; $c->name = $name; $c->leader = $boss; if (!$c->save()) { var_export($c->errors); } } } } } } }
public static function createNew($data) { $c = new Club(); $c->name = $data['club_name']; $c->save(); return $c; }
/** * Creates a new Club model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Club(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(ClubFormRequest $request) { $club = new Club(); $club->name = $request->get('name'); $club->slug = $request->get('slug'); $club->description = $request->get('description'); $club->photo = $request->get('photo'); $club->website = $request->get('website'); $club->facebook = $request->get('facebook'); $club->slack = $request->get('slack'); $club->save(); return Redirect::route('admin::club-create')->with('success', 'The club has been created successfully'); }
public function actionCreateClub() { User::redirectOnHomepageIfGuest($this); $model = new Club(); $image = new UploadImage(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { $tmp = []; for ($i = 1; $i <= 8; ++$i) { $tmp[] = $i; } $tmp[] = 13; $model->date = date('Y-m-d H:i:s'); $model->photo_count = 0; $model->id_author = Yii::$app->user->getId(); $model->user_count = 1; $model->rating = 1 + mt_rand() % 100000000.0 / 10000000000000.0; $cl = Yii::$app->request->post('Club'); $model->close_comments = isset($cl['close_comments']) ? 1 : 0; if (!$model->style) { $model->style = 1; } if (!$model->background) { $model->background = 1; } //якщо пробували підмінити деякі дані if (!in_array($model->type, [1, 2]) || !in_array($model->background, $tmp) || !Category::isSetCategory($model->id_level_1)) { return $this->redirect('/'); } // збереження табнейла $image->file = UploadedFile::getInstance($image, 'file'); if ($image->file && $image->validate()) { $model->img_src = md5(uniqid(mt_rand())) . '.' . $image->file->extension; $image->savePhotoThumbnail($model->img_src); } else { $model->img_src = ''; // \Yii::$app->getSession()->setFlash('notify', 'при збереженні табнейла сталася помилка'); } if ($model->save()) { Club::addNewUser($model->id, Yii::$app->user->getId(), 1); return $this->redirect('/club' . $model->id); \Yii::$app->getSession()->setFlash('notify', 'Клуб успішно створено!'); } else { echo '<pre>'; print_r($model); echo '</pre>'; die; } } $colors = Yii::$app->params['club_colors']; $all_categories = Category::getAllTranslatedCategory(); return $this->render('settings', ['action' => 'Створення клубу', 'model' => $model, 'colors' => $colors, 'image' => $image, 'all_categories' => $all_categories]); }