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]); }
public function getIds($topic_names) { $topic_ids = []; if ($topic_names !== '') { foreach (explode(',', $topic_names) as $topic_name) { $topic = Topic::where('name', $topic_name)->get()->first(); if (!$topic) { $topic = new Topic(['name' => $topic_name]); $topic->save(); } $topic_ids[] = $topic->id; } } return $topic_ids; }
/** * 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.')); } } }
/** * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function simpantopik(Request $request) { $input = $request->all(); $validator = $this->topic_validator($input); if ($validator->fails()) { $this->throwValidationException($request, $validator); } //Topic::create($input); $topic = new Topic(); $topic->pertemuan_ke = $input['pertemuan_ke']; $topic->tanggal = $input['tanggal']; //seek kode seksi given current Kode_Matkul & running semester $course = Course::instanceByKodeMatkul($input['Kode_Matkul']); $topic->kode_seksi = $course->seksi; $topic->nama_topik = $input['nama_topik']; $topic->jumlah_mhs = $input['jumlah_mhs']; $topic->save(); //$topic return $this->showTopic(); }
/** * 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]); } }