public function actionNew() { $request = Yii::$app->getRequest(); $topic = new Topic(['scenario' => Topic::SCENARIO_NEW, 'user_id' => Yii::$app->getUser()->id]); $content = new TopicContent(); if ($topic->load($request->post()) && $topic->validate() && $content->load($request->post()) && $content->validate() && $topic->save(false)) { $content->link('topic', $topic); return $this->redirect(['view', 'id' => $topic->id]); } return $this->render('new', ['model' => $topic, 'content' => $content]); }
/** * Creates a new Topic model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate($id) { $model = new Topic(); if ($model->load(Yii::$app->request->post())) { $model->node_id = $id; if ($model->save()) { return $this->redirect(['view', 'id' => $model->id]); } } return $this->render('create', ['model' => $model]); }
/** * Creates a new Topic model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { if (Yii::$app->user->can('topicCreate')) { $model = new Topic(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id, 'Category_id' => $model->Category_id]); } else { return $this->render('create', ['model' => $model]); } } else { if (Yii::$app->user->isGuest) { Yii::$app->user->loginRequired(); } else { throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.')); } } }
/** * 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(); if ($model->load(Yii::$app->request->post())) { $model->blog_id = 2; $model->user_id = 2; $model->topic_date_add = date("Y-m-d H:i:s"); $model->topic_user_ip = $_SERVER['REMOTE_ADDR']; $model->topic_text_hash = '0'; if ($model->save()) { return $this->redirect('?r=topic-content/create&topic_id=' . $model->topic_id); } else { var_dump($model->errors); } } else { return $this->render('create', ['model' => $model]); } }