當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Post::insert方法代碼示例

本文整理匯總了PHP中app\models\Post::insert方法的典型用法代碼示例。如果您正苦於以下問題:PHP Post::insert方法的具體用法?PHP Post::insert怎麽用?PHP Post::insert使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\models\Post的用法示例。


在下文中一共展示了Post::insert方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: run

 public function run()
 {
     DB::table('Posts')->delete();
     Post::insert(['title' => 'First Post', 'slug' => 'first-post', 'excerpt' => 'First Post body', 'content' => 'Content First Post body', 'published' => true, 'published_at' => DB::raw('CURRENT_TIMESTAMP')]);
     Post::insert(['title' => 'Second Post', 'slug' => 'second-post', 'excerpt' => 'Second Post body', 'content' => 'Content Second Post body', 'published' => false, 'published_at' => DB::raw('CURRENT_TIMESTAMP')]);
     Post::insert(['title' => 'Third Post', 'slug' => 'third-post', 'excerpt' => 'Third Post body', 'content' => 'Content Third Post body', 'published' => false, 'published_at' => DB::raw('CURRENT_TIMESTAMP')]);
 }
開發者ID:spshe4,項目名稱:car.base,代碼行數:7,代碼來源:DatabaseSeeder.php

示例2: add_post

 public function add_post()
 {
     $validator = models\Post::validator('add');
     if (!empty($_POST)) {
         if ($validator->validate($_POST)) {
             $insert = $validator->output;
             $insert['author_id'] = $this->user->UserID();
             $insert['created_on'] = time();
             if ($pid = models\Post::insert($insert)) {
                 $post = models\Post::get($pid);
                 Session::success('Post Created. Look:');
                 // Send e-mail to $this->user's followers
                 /*					foreach ( $this->user->user->followers AS $user ) {
                 						Email::make($user->email, 'New post by '.$user, $user.' posted a new message on the blog. Read it at '.$post->url(array('absolute' => true)))->send();
                 					}*/
                 $this->_redirect($post->url());
             }
             Session::error('Couldn\'t save... =( Try again!?');
         }
     }
     $categories = $validator->options->categories;
     $messages = Session::messages();
     return $this->tpl->display('blog/post_form', get_defined_vars());
 }
開發者ID:rudiedirkx,項目名稱:Rudie-on-wheels,代碼行數:24,代碼來源:blogController.php


注:本文中的app\models\Post::insert方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。