/** * Creates a new Content model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Content(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function postCreate(Request $request) { $this->validate($request, ['caption' => 'required', 'description' => 'required', 'text' => 'required']); $content = new Content(); $data = $request->only(['category_id', 'active', 'publish_at', 'caption', 'description', 'text']); $data['publish_at'] = Carbon::createFromFormat('d.m.Y', $data['publish_at']); $content->fill($data); $content->save(); return redirect(\URL::action('Backend\\ArticleController@getIndex')); }
/** * Creates a new Content model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Content(); if ($model->load(Yii::$app->request->post())) { $model->data = date('Y-m-d h:i:s'); $model->user_id = Yii::$app->user->getId(); if ($model->save()) { return $this->redirect(['view', 'id' => $model->id, 'user_id' => $model->user_id]); } } return $this->render('create', ['model' => $model]); }
public function actionCreate() { $token = \Yii::$app->request->headers->get('token'); $content = \Yii::$app->request->post()['content']; $create_content = new Content(); $create_content->content = $content; $create_content->author_id = $token; if (isset($token) && $create_content->save()) { $array = ['error_no' => 0, 'error_msg' => '']; echo json_encode($array); } }
/** * Creates a new Content model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Content(); //$data = new Category(); //$data = Category::find()->all(); if ($model->load(Yii::$app->request->post())) { $model->create_time = time(); $model->user_id = \Yii::$app->user->id; $model->save(); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function actionIndex() { //print_r(CKEditor::className()); //print_r(Yii::$classMap['yii\web\Controller']); $model = new Content(); //print_r(Yii::$app->request->post()); if (Yii::$app->request->isPost && $model->load(Yii::$app->request->post())) { if ($model->save()) { //TODO echo '成功'; } } return $this->render('index', ['model' => $model]); }
protected function migrate_serba_serbi() { $website = Website::first(); $data_users = User::get(); foreach ($data_users as $user) { $users[$user['username']] = $user; } // get old articles DB::connection('mongodb')->collection('posts')->where('category', 'regex', '/serba/i')->chunk(1000, function ($data) use($new_collection, $users, $website) { foreach ($data as $x) { unset($tags); $tags[] = 'serba-serbi'; if (str_is('*tokoh*', strtolower($x['title']))) { $tags[] = 'tokoh'; } if ($x['tgl_published']) { $news = new Content(['title' => $x['title'], 'slug' => str_replace('.', '', $x['url']), 'summary' => str_limit(strip_tags(str_replace("\n", "", $x['full'])), 125), 'content' => $x['full'], 'published_at' => date('Y-m-d H:i:s', $x['tgl_published']->sec), 'created_at' => $x['tgl'], 'updated_at' => $x['tgl'], 'user_id' => array_key_exists($x['author'], $users) ? $users[$x['author']]->id : $users['dita']->id]); if (!$news->save()) { print_r($news->toArray()); dd($news->getErrors()); } // ---------------------------------------------------------------------------------------------------- // IMAGE // ---------------------------------------------------------------------------------------------------- $s_image = new Image(['name' => 'sm', 'path' => $x['thumbmail'], 'title' => '', 'description' => '']); $m_image = new Image(['name' => 'md', 'path' => $x['image'], 'title' => '', 'description' => '']); $l_image = new Image(['name' => 'lg', 'path' => $x['image'], 'title' => '', 'description' => '']); $news->images()->updateOrCreate(['name' => 'sm'], $s_image->toArray()); $news->images()->updateOrCreate(['name' => 'md'], $m_image->toArray()); $news->images()->updateOrCreate(['name' => 'lg'], $l_image->toArray()); // ---------------------------------------------------------------------------------------------------- // TAG // ---------------------------------------------------------------------------------------------------- unset($tags_model); $tags_model = new Collection(); foreach ($tags as $tag) { $tags_model[] = Tag::firstOrCreate(['name' => $tag]); } foreach ($tags_model as $k => $v) { if (!$tags_model[$k]->save()) { dd($tags_model[$k]->getErrors()); } } if (count($tags_model)) { $news->tags()->sync($tags_model->lists('id')); } // ---------------------------------------------------------------------------------------------------- // WEBSITE // ---------------------------------------------------------------------------------------------------- $news->websites()->sync([$website->id]); // ---------------------------------------------------------------------------------------------------- // LOG // ---------------------------------------------------------------------------------------------------- // $news->authored()->attach(array_key_exists($x['author'], $users) ? $users[$x['author']]->id : $users['dita']->id, ['original_data' => json_encode([]), 'updated_data' => $news->toJson()]); } // $news->websites()->associate($website); // $news->save(); } }); // save to new tables }