public function actionCreate($node = null) { if (Yii::$app->user->isGuest) { Yii::$app->getSession()->setFlash('danger', '你需要登陆之后才能创作新主题'); return $this->redirect('/account/login?next=/topic/create'); } if (Yii::$app->user->identity->email_status == 0) { $this->goHome(); } $this->title = '创作新主题 - ' . Yii::$app->name; $this->description = ''; if (!empty($node)) { if (($model = Node::findOne(['enname' => $node])) !== null) { $node = $model; } else { $node = null; } } $model = new Topic(); if (!empty($node)) { $model->node_id = $node->id; } $topicContent = new TopicContent(); if ($model->load(Yii::$app->request->post()) && $model->create()) { $this->redirect('/topic/' . $model->id); } else { return $this->render('create', ['model' => $model, 'node' => $node, 'topicContent' => $topicContent]); } }
/** * Action method for creating a new forum topic. * @return string|Response action method execution result. */ public function actionCreate() { $topic = new Topic(); if ($topic->load(Yii::$app->request->post()) && $topic->save()) { return $this->redirect($topic->url); } return $this->render('create', ['topic' => $topic, 'categories' => Category::find()->all(), 'sections' => empty($topic->category_id) ? [] : Section::findAll(['category_id' => $topic->category_id])]); }
/** * Creates a new Topic model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Topic(); $model->loadDefaultValues(); $model->setScenario('update'); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model, 'tags' => Tag::find()->all()]); } }