示例#1
0
 public function load(ObjectManager $manager)
 {
     $i = 1;
     $faker = \Faker\Factory::create();
     while ($i <= 100) {
         $post = new Post();
         $post->setTitle($faker->sentence(4));
         $post->setLead($faker->text($maxNbChars = 10));
         $post->setBody($faker->text($maxNbChars = 400));
         $post->setImage($faker->word($maxNbChars = 14) . '.jpg');
         $post->setStatus($post::PUBLISHED);
         $fakerPublishDate = $faker->dateTimeBetween('-1 years', '+1 month');
         $post->setPublishedAt($fakerPublishDate);
         $post->setCreatedAt($post->getPublishedAt());
         $post->setUpdatedAt($post->getPublishedAt());
         $rand = rand(1, 10);
         $post->setAuthor($this->getReference('user-' . $rand));
         $rand = rand(1, 6);
         $post->setCategory($this->getReference('category-' . $rand));
         $post->setTags('symfony2, php');
         $manager->persist($post);
         $this->addReference('post-' . $i, $post);
         ++$i;
     }
     $manager->flush();
 }