本文整理汇总了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')]);
}
示例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());
}