Exemple #1
0
 public function load(ObjectManager $em)
 {
     $post_blog = new Post();
     $post_blog->setCategory($em->merge($this->getReference('category-blog')));
     //manyToOne
     $post_blog->setTitle('Learn the Bootstrap Grid in <b>15 Minutes</b>');
     $post_blog->setExcerpt($this->getPostExcerpt());
     $post_blog->setContent($this->getPostContent());
     //$post_blog->setExcerpt('Bootstrap is the most widely used frontend framework right now.');
     //$post_blog->setContent('Bootstrap is the most widely used frontend framework right now. When it comes to building responsive websites and apps, it’s the first choice of both professionals and hobbyists because of how simple it is to work with. Anybody who knows HTML, CSS and a bit of JavaScript can learn Bootstrap in no time.');
     $post_blog->setAuthorEmail('*****@*****.**');
     $post_blog->setViewsPost(10);
     $post_blog->addTag($em->merge($this->getReference('tag-html')));
     //manyToMany
     $post_blog->addTag($em->merge($this->getReference('tag-css')));
     //manyToMany
     $post_blog->setPublishedAt(new \DateTime('now - 1 days'));
     $post_shop = new Post();
     $post_shop->setCategory($em->merge($this->getReference('category-shop')));
     //manyToOne
     $post_shop->setTitle('How to Control <b>YouTube Video Player</b> with jQuery');
     $post_shop->setExcerpt($this->getPostExcerpt());
     $post_shop->setContent($this->getPostContent());
     //$post_shop->setExcerpt('YouTube has become the standard way for delivering high quality video on the web.');
     //$post_shop->setContent('YouTube has become the standard way for delivering high quality video on the web. Sometimes, when you embed a video in your web application or landing page, you need a great deal of control on what and how is displayed. This is why we are going to show you how you can use the YouTube JavaScript Player API.');
     $post_shop->setAuthorEmail('*****@*****.**');
     $post_shop->setViewsPost(5);
     $post_shop->addTag($em->merge($this->getReference('tag-html')));
     //manyToMany
     $post_shop->addTag($em->merge($this->getReference('tag-php')));
     //manyToMany
     $post_shop->addTag($em->merge($this->getReference('tag-ajax')));
     //manyToMany
     $post_shop->setPublishedAt(new \DateTime('now - 1 days'));
     $em->persist($post_blog);
     $em->persist($post_shop);
     foreach (range(0, 30) as $i) {
         $post = new Post();
         $post->setCategory($this->getRandomCategory($em));
         //manyToOne
         $post->setTitle($this->getRandomTitle($i));
         $post->setExcerpt($this->getPostExcerpt());
         $post->setContent($this->getPostContent());
         $post->setAuthorEmail($this->getRandomAuthorEmail());
         $post->setViewsPost(rand(0, 15));
         $post->setPublishedAt(new \DateTime('now -' . (5 + $i) . 'days'));
         foreach ($this->getRandomTag($em) as $tag) {
             $post->addTag($tag);
             //manyToMany
         }
         $em->persist($post);
         $this->addReference('post-post' . $i, $post);
     }
     $em->flush();
     $this->addReference('post-blog', $post_blog);
     $this->addReference('post-shop', $post_shop);
 }