public function actionAdd() { if (User::thisUser()->reputation < School::MIN_REPUTATION_SCHOOL_CREATE) { return Yii::$app->getResponse()->redirect(Url::home()); } $school = new School(); if ($school->load(Yii::$app->request->post())) { $schoolPost = Yii::$app->request->post('School'); $school->country = $schoolPost['country']; $school->description = \yii\helpers\HtmlPurifier::process($school->description, []); $school->user_id = Yii::$app->user->identity->getId(); $school->date = strtotime(date('Y-m-d')); $school->like_count = 0; $school->show_count = 0; if ($school->save()) { // Добавляем теги $tagsArr = explode(',', Yii::$app->request->post('tags')); $school->saveTags($tagsArr); // Добавляем картинки к записи $imgs = Yii::$app->request->post('imgs'); if (!empty($imgs) && is_array($imgs)) { $school->saveImgs($imgs); } else { $school->saveImgs([]); } $school->saveLocations(Yii::$app->request->post('location')); return Yii::$app->getResponse()->redirect($school->getUrl()); } } Yii::$app->params['jsZoukVar']['tagsAll'] = Tags::getTags(Tags::TAG_GROUP_ALL); return $this->render('add', ['school' => $school]); }
/** * Creates a new School model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new School(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->school_id]); } else { return $this->render('create', ['model' => $model]); } }
public function actionAdd() { $model = new School(); if ($model->load(Yii::$app->request->post())) { if ($model->save()) { Yii::$app->session->setFlash('success', '成功添加学校“' . $model->name . '”。'); return $this->redirect(['index']); } else { Yii::$app->session->setFlash('danger', '添加学校失败。'); } } return $this->render('form', ['model' => $model]); }