/** * create a post * * @return null|string|\yii\web\Response * @throws Exception * @throws \Exception */ public function actionCreate() { try { Yii::trace('Trace :' . __METHOD__, __METHOD__); $response = null; $model = new Post(['scenario' => 'create']); $query = (new Query())->select('name, id')->from('categories')->all(); $categories = ArrayHelper::map($query, 'id', 'name'); if ($model->load($_POST) === true && $model->validate() === true) { $model->category_id = (int) $model->category_name; $model->created = Yii::$app->formatter->asDateTime('now', 'php:Y-m-d H:i:s'); $model->user_id = Yii::$app->user->id; $status = $model->save(); if ($status === true) { $sidebarCacheName = isset(Yii::$app->params['cache']['sidebar']) ? Yii::$app->params['cache']['sidebar'] : null; if ($sidebarCacheName !== null) { Yii::$app->cache->delete($sidebarCacheName); } $response = $this->redirect(['/post/view', 'slug' => $model->slug]); } } if ($response === null) { $response = $this->render('create', ['model' => $model, 'categories' => $categories]); } return $response; } catch (Exception $e) { Yii::error($e->getMessage(), __METHOD__); throw $e; } }
/** * Creates a new Post model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Post(); $currentUser = \Yii::$app->user->identity; if (!$currentUser->isAuthor()) { //不是 作者 无权操作 return $this->goHome(); } if ($model->load(Yii::$app->request->post())) { if (isset($model->user_id) || $currentUser->id != $model->user_id && !$currentUser->isAdmin()) { $model->user_id = $currentUser->id; } $model->user_id = $currentUser->id; //处理slug $title = mb_strlen($model->title, 'utf8') > 6 ? mb_substr($model->title, 0, 5) : $model->title; $model->slug = \app\helpers\Pinyin::encode($title, 'all'); while (Post::getPostBySlug($model->slug)) { $model->slug .= '-1'; } if ($model->save()) { $this->flash('发布成功!', 'info'); return $this->redirect(['update', 'id' => $model->id]); } } $model->comment_status = Post::COMMENT_STATUS_OK; $model->user_id = $currentUser->id; return $this->render('create', ['model' => $model, 'isAdmin' => $currentUser->isAdmin()]); }
/** * new-Action (Formularauswertung) */ public function postNew() { //$validator = Validator::make(Request::all(), Post::$rules); //if (/*$validator->passes()*/) //{ // validation has passed, save user in DB $post = new Post(); $post->title = " "; $post->content = Request::input('content'); $user = Auth::user(); $post->link = ''; $post->user_id = $user->id; $post->event_id = Request::input('event_id'); $post->save(); $response = new \stdClass(); $response->success = true; $response->total = 1; $response->data = $post; return response()->json($response); //} /*else { // validation has failed, display error messages $response = new \stdClass; $response->success = false; $response->total = 1; return response()->json($response); }*/ }
/** * Create or update a post. * * @param App\Models\Post $post * @param array $inputs * @param bool $user_id * @return App\Models\Post */ private function savePost($post, $inputs, $user_id = null) { $post->title = $inputs['title']; $post->slug = $inputs['slug']; $post->active = isset($inputs['active']); $post->save(); return $post; }
public function writePost() { $postValue = \Input::get('Post'); $post = new Post(); $post->fill($postValue); $post->setAttribute('user_id', \Auth::user()->id); $post->save(); return redirect(route('home')); }
/** * Creates a new Post model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Post(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model, 'category' => Category::find()->all(), 'authors' => User::find()->all()]); } }
/** * Create or update a post. * * @param App\Models\Post $post * @param array $inputs * @param bool $user_id * @return App\Models\Post */ private function savePost($post, $inputs, $user_id = null) { $post->titulo = $inputs['titulo']; $post->descripcion = $inputs['contenido']; $post->imagens = $inputs['content']; $post->imagenl = $inputs['slug']; $post->save(); return $post; }
public function getNew() { $post = new Post(); $post->user_id = 1; $post->title = md5(time() * rand()); $post->content = md5(time() * rand()); $post->link = ''; $post->save(); }
/** * Update the specified resource in storage. * * @param PostFormRequest $request * @param Post $post * @return Response */ public function update(PostFormRequest $request, $post) { $post->fill($request->all()); $post->save(); if ($tags = $request->input('tags')) { $post->retag($request->input('tags')); } return $post->load('tagged'); }
/** * Creates a new Post model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Post(); 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 actionCreate() { $model = new Post(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['list']); } else { $model->status = POST::STATUS_ENABLED; return $this->render('create', ['model' => $model]); } }
public function new_post(Request $request) { $post = new Post(); $post->author_id = Auth::user()->id; $post->is_draft = true; $post->content = "# Intro\n" . "Go ahead, play around with the editor! Be sure to check out **bold** and *italic* styling, or even [links](http://google.com). You can type the Markdown syntax, use the toolbar, or use shortcuts like `cmd-b` or `ctrl-b`.\n\n" . "# Lists\n" . "Unordered lists can be started using the toolbar or by typing `* `, `- `, or `+ `. Ordered lists can be started by typing `1. `.\n\n" . "#### Unordered\n" . "* Lists are a piece of cake\n" . "* They even auto continue as you type\n" . "* A double enter will end them\n" . "* Tabs and shift-tabs work too\n\n" . "#### Ordered\n" . "1. Numbered lists...\n" . "2. ...work too!\n\n" . "## What about images?\n" . "![Yes](http://i.imgur.com/sZlktY7.png)"; $post->image = "outdoor-bg.jpg"; $post->save(); return view('post.create', ['post' => $post]); }
/** * Create post * * @param Request $request * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View */ public function create(Request $request) { if ($request->isMethod("post")) { $rules = ["title" => "required", "alias" => "required|unique:posts,alias", "content" => "required", 'image' => 'mimes:jpeg,jpg,png']; Validator::make($request->all(), $rules)->validate(); $post = new Post(); $post->title = $request->input("title"); $post->alias = $request->input("alias"); $post->content = $request->input("content"); $post->meta_keys = $request->input("meta_keys"); $post->meta_desc = $request->input("meta_desc"); if (!empty($request->file("image"))) { $generated_string = str_random(32); $file = $request->file("image")->store('uploads'); $new_file = $generated_string . '.' . $request->file("image")->getClientOriginalExtension(); Storage::move($file, 'uploads/' . $new_file); $img = Image::make($request->file('image')); $img->crop(200, 200); $img->save(storage_path('app/public/uploads/' . $new_file)); $img = Image::make($request->file('image')); $img->resize(600, 315); $img->save(storage_path('app/public/uploads/fb-' . $new_file)); $post->image = $new_file; } if ($request->has("category")) { $post->category_id = $request->input("category"); } $post->publish = $request->has("publish"); $post->author_id = Auth::user()->id; $post->save(); if ($request->has("tags")) { foreach ($request->input("tags") as $tag) { $post_tag = new PostTag(); $post_tag->post_id = $post->id; $post_tag->tag_id = $tag; $post_tag->save(); } } $admins = User::getAdmins(); foreach ($admins as $admin) { if ($admin->id != Auth::user()->id) { $notification = new Notification(); $notification->from = Auth::user()->id; $notification->to = $admin->id; $notification->type = 3; $notification->save(); } } return redirect()->route('posts'); } else { $categories = Category::getCategoriesByPublish(); $tags = Tag::getTags(); return view("site.post.create", compact("categories", "tags", "post")); } }
/** * Create a new post with a text message * * @param \App\Models\Provider $provider * @param string $message * @return \App\Models\Post */ public function createMessage($provider, $message) { $post = new Post(); $post->service = $provider->service; $post->message = $message; $post->user_id = $provider->user_id; $post->provider_id = $provider->id; $post->scheduled_at = time(); $post->save(); return $post; }
public static function CreatePost($board_id, $description, $photo_link, $user_id, $place_id, $hashtag) { $post = new Post(); $post->description = $description; $post->photo_link = $photo_link; $post->user_id = $user_id; $post->board_id = $board_id; $post->place_id = $place_id; $post->hashtag = $hashtag; $post->save(); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $post = new \App\Models\Post(); $json = json_decode(\Request::input('json')); $receiver = \Request::input('receiver'); $post->text = \Request::input('text'); $post->sender_id = Auth::user()->id; $post->receiver_id = User::where('name', '=', $receiver)->first()->id; $post->save(); return \Redirect::to('/post/'); }
/** * Creates a new Post model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Post(); $model->author_name = Yii::$app->user->identity->nickname; if ($model->load(Yii::$app->request->post())) { $model->author_id = Yii::$app->user->id; if ($model->save()) { return $this->redirect(['view', 'id' => $model->id]); } } return $this->render('create', ['model' => $model]); }
/** * Create or update a post. * * @param App\Models\Post $post * @param array $inputs * @param bool $user_id * @return App\Models\Post */ private function savePost($post, $inputs, $user_id = null) { $post->title = $inputs['title']; $post->summary = $inputs['summary']; $post->content = $inputs['content']; $post->slug = $inputs['slug']; $post->active = isset($inputs['active']); if ($user_id) { $post->user_id = $user_id; } $post->save(); return $post; }
/** * Creates a new Post model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Post(); $createdAt = time(); $model->created_at = $createdAt; $model->updated_at = $createdAt; if ($model->load(Yii::$app->request->post()) && $model->save()) { $this->saveCategoriesList($model); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model, 'categoriesList' => $this->getCategoriesList()]); } }
/** * Seeds the table. * * @return void */ public function run() { $post = new Post(); $post->title = 'JSON API paints my bikeshed!'; $post->body = 'If you\'ve ever argued with your team about the way your JSON responses should be ' . 'formatted, JSON API is your anti-bikeshedding weapon.'; /** @var Site $site */ $site = Site::firstOrFail(); /** @var Author $author */ $author = Author::firstOrFail(); $post->site_id = $site->id; $post->author_id = $author->id; $post->save(); }
public function store(Request $request) { $input = $request->all(); $validator = Validator::make($input, Post::getCreateRules()); if ($validator->passes()) { $post = new Post(); $post->user_id = $request->user_id; $post->text = $request->text; $post->save(); return $this->response->array($post); } else { throw new \Dingo\Api\Exception\StoreResourceFailedException('Could not create new user.', $validator->errors()); } }
/** * Creates a new Post model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Post(); if ($model->load(Yii::$app->request->post())) { $model->datetime = date("Y-m-d H:i:s"); $model->Participant_id = Yii::$app->user->id; if ($model->save()) { return $this->redirect(['view', 'id' => $model->id]); } //die(var_dump($model->getErrors())); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Post model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Post(); if ($model->load(Yii::$app->request->post()) && $model->save()) { /** @var Category[] $categories */ $categories = Category::find()->where(['id' => $model->categories_id])->all(); foreach ($categories as $category) { $model->link('categories', $category); } return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model, 'category_names' => ArrayHelper::map(Category::find()->all(), 'id', 'name')]); } }
/** * Creates a new Post model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Post(); $post = Yii::$app->request->post(); if ($model->load($post)) { $model->user_id = $userId = \Yii::$app->user->identity->id; if ($model->save()) { return $this->redirect(Yii::$app->request->referrer); } } elseif (Yii::$app->request->isAjax) { return $this->renderAjax('_form', ['model' => $model]); } else { return $this->render('_form', ['model' => $model]); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $content = $this->getDocument(); $attributes = array_get($content, 'data.attributes', []); $attributes['author_id'] = array_get($content, 'data.links.author.linkage.id', null); $attributes['site_id'] = array_get($content, 'data.links.site.linkage.id', null); $rules = ['title' => 'required', 'body' => 'required', 'author_id' => 'required|integer', 'site_id' => 'required|integer']; $validator = Validator::make($attributes, $rules); if ($validator->fails()) { throw new BadRequestHttpException(); } $post = new Post($attributes); $post->save(); return $this->getCreatedResponse($post); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { // $post = new Post(); $post->user_id = Request::input('user_id'); $post->content = Request::input('content'); $post->title = Request::input('title'); $post->link = Request::input('link'); $post->save(); $response = new \stdClass(); $response->success = true; $response->total = 1; $response->data = $post; return response()->json($response); }
public function actionNew() { $postModel = new Post(); $category = new Category(); $categoryList = ArrayHelper::map($category->find()->asArray()->all(), 'id', 'title'); $postList = $postModel->find()->asArray()->all(); $message = ''; if ($postModel->load(Yii::$app->request->post()) && $postModel->save()) { $selectedCategories = Category::find()->where(['id' => $postModel->categoryIds])->all(); foreach ($selectedCategories as $category) { $postModel->link('categories', $category); } $message = 'Category added success'; } return $this->render('new', ['model' => $postModel, 'message' => $message, 'categoryList' => $categoryList, 'postList' => $postList]); }
/** * Creates a new Post model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Post(); $model->create_at = $model->update_at = $model->reply_at = time(); $model->user_id = User::getCurrentId(); if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($model->point_id > 0) { $point = Point::findOne($model->point_id); $point->post_num += 1; $point->save(); } return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model, 'point' => Point::findOne(isset($_GET['point']) ? $_GET['point'] : '')]); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store(PostFormRequest $request) { $post = new Post(); $post->title = $request->get('title'); $post->body = $request->get('body'); $post->slug = str_slug($post->title); $post->author_id = $request->user()->id; if ($request->has('save')) { $post->active = 0; $message = 'Post saved successfully'; } else { $post->active = 1; $message = 'Post published successfully'; } $post->save(); return redirect('edit/' . $post->slug)->withMessage($message); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $this->checkParametersEmpty(); $content = $this->getDocument(); $attributes = array_get($content, 'data.attributes', []); $attributes['author_id'] = array_get($content, 'data.relationships.author.data.id', null); $attributes['site_id'] = array_get($content, 'data.relationships.site.data.id', null); /** @var \Illuminate\Validation\Validator $validator */ $rules = ['title' => 'required', 'body' => 'required', 'author_id' => 'required|integer', 'site_id' => 'required|integer']; $validator = Validator::make($attributes, $rules); if ($validator->fails()) { throw new ValidationException($validator); } $post = new Post($attributes); $post->save(); return $this->getCreatedResponse($post); }