Beispiel #1
0
 /**
  * Create and load posts fixtures to database
  *
  * @param ObjectManager $manager Entity manager object
  */
 public function load(ObjectManager $manager)
 {
     $adminUser = $this->getReference('user-admin');
     $secondUser = $this->getReference('user-second');
     $symfonyTag = $this->getReference('tag-symfony2');
     $doctrine2Tag = $this->getReference('tag-doctrine2');
     // posts
     $postFirst = new Post();
     $postFirst->setTitle('My first post');
     $postFirst->setSlug('my-first-post');
     $postFirst->setText('In work we use Symfony2.<!--more-->And text after cut');
     $postFirst->addTag($symfonyTag);
     $postFirst->addTag($doctrine2Tag);
     $postFirst->setAuthor($adminUser);
     $postFirst->setPublished(true);
     $manager->persist($postFirst);
     $manager->merge($symfonyTag);
     $manager->merge($doctrine2Tag);
     $postAboutPhp = new Post();
     $postAboutPhp->setTitle('Post about php');
     $postAboutPhp->setSlug('post-about-php');
     $postAboutPhp->setText('The PHP development team would like to announce the immediate availability of PHP 5.3.6.');
     $postAboutPhp->addTag($symfonyTag);
     $postAboutPhp->addTag($doctrine2Tag);
     $postAboutPhp->setAuthor($secondUser);
     $postAboutPhp->setPublished(true);
     $manager->persist($postAboutPhp);
     $manager->merge($symfonyTag);
     $manager->merge($doctrine2Tag);
     $manager->flush();
     $this->addReference('post-first', $postFirst);
     $this->addReference('post-about-php', $postAboutPhp);
 }
 /**
  * Create and load posts fixtures to database
  *
  * @param ObjectManager $manager Entity manager object
  */
 public function load(ObjectManager $manager)
 {
     $phpTag = $this->getReference('tag-php');
     $firstUser = $this->getReference('user-first');
     $createdAt = new \DateTime();
     for ($i = 1; $i <= 12; $i++) {
         $post = new Post();
         $title = 'Post for paginator #' . $i;
         $post->setTitle($title);
         $post->setSlug('post-for-paginator-' . $i);
         $text = 'Generally this bundle is based on Knp Pager component. This component introduces a different way for pagination handling. You can read more about the internal logic on the given documentation link.' . $i;
         $post->setText($text);
         $post->addTag($phpTag);
         $post->setAuthor($firstUser);
         $post->setCreated(clone $createdAt->modify("+{$i} day"));
         $post->setPublished(true);
         $post->addTranslation(new PostTranslation('en', 'title', 'EN ' . $title));
         $post->addTranslation(new PostTranslation('en', 'text', 'EN ' . $text));
         $manager->persist($post);
         $manager->merge($phpTag);
     }
     $manager->flush();
 }