Beispiel #1
0
 /**
  * ダミーの投稿(\Tinitter\Model\Post)を指定数だけ生成保存する
  * @param $num 生成する数
  */
 public static function farmingPost($num)
 {
     $faker = \Faker\Factory::create();
     for ($i = 0; $i < $num; $i++) {
         $post = new M_Post();
         $post->nickname = $faker->firstName;
         $post->body = $faker->paragraph(2);
         $post->save();
     }
 }
Beispiel #2
0
 /**
  * Postが作成できるか、取得できるか
  */
 public function testPostCreate()
 {
     // 一件保存
     $post = new M_Post();
     $post->nickname = 'nickname';
     $post->body = 'body';
     $post->save();
     // 正しく保存されたか確認
     $id = $post->id;
     $same_post = M_Post::findOrFail($id);
     $this->assertEquals($same_post->nickname, 'nickname');
     $this->assertEquals($same_post->body, 'body');
 }
Beispiel #3
0
 public function commit()
 {
     $app = \Slim\Slim::getInstance();
     $params = $app->request->params();
     $error_list = V_Post::byArray($params);
     if (empty($error_list)) {
         $post = new M_Post();
         $post->nickname = $params['nickname'];
         $post->body = $params['body'];
         $post->save();
         $app->redirect('/');
     } else {
         $app->render('Post/form.twig', ['params' => $params, 'error_list' => $error_list]);
     }
 }