本文整理汇总了PHP中app\models\Post::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::save方法的具体用法?PHP Post::save怎么用?PHP Post::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Post
的用法示例。
在下文中一共展示了Post::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* 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;
}
}
示例2: actionCreate
/**
* 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()]);
}
示例3: postNew
/**
* 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);
}*/
}
示例4: savePost
/**
* 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;
}
示例5: writePost
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'));
}
示例6: actionCreate
/**
* 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()]);
}
}
示例7: savePost
/**
* 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;
}
示例8: getNew
public function getNew()
{
$post = new Post();
$post->user_id = 1;
$post->title = md5(time() * rand());
$post->content = md5(time() * rand());
$post->link = '';
$post->save();
}
示例9: update
/**
* 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');
}
示例10: actionCreate
/**
* 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]);
}
}
示例11: actionCreate
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]);
}
}
示例12: new_post
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]);
}
示例13: create
/**
* 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"));
}
}
示例14: createMessage
/**
* 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;
}
示例15: CreatePost
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();
}