/**
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     for ($i = 0; $i < 3; $i++) {
         $article = new Article();
         $article->setTitle('Article de test ' . $i);
         $article->setSlug($article->getTitle());
         $article->setContent($this->articleContent[$i]);
         $article->setExtract($this->articleExtract[$i]);
         $article->setCategory($this->getReference('category'));
         $article->setAuthor($this->getReference('user'));
         $article->setPictureName('default-image-' . $i . '.jpg');
         $manager->persist($article);
         // Reference added once
         if ($i == 0) {
             $this->addReference('article', $article);
         }
     }
     $manager->flush();
 }
Пример #2
0
 public function load(ObjectManager $manager)
 {
     $faker = Factory::create();
     for ($i = 1; $i <= 24; $i++) {
         $article = new Article();
         // $article->setSlug('article' . $i);
         $article->setSummary($faker->sentences(10, true));
         $article->setContent($faker->text(3000));
         $article->setTitle($faker->sentence());
         $slug = $this->container->get('app.slugger')->slugify($article->getTitle());
         $article->setSlug($slug);
         $article->setAuthorEmail('*****@*****.**');
         $article->setPathToImage('images/foto_' . $i . '.jpg');
         for ($j = 1; $j <= 5; $j++) {
             $comment = new Comment();
             $comment->setContent($faker->sentences(5, true));
             //$comment->setPublishedAt(new \DateTime('now'));
             $comment->setArticle($article);
             $comment->setAuthorEmail('*****@*****.**');
             $article->addComment($comment);
             $manager->persist($comment);
         }
         $manager->persist($article);
         $arrayId = array();
         $k = rand(1, 10);
         while (count($arrayId) < $k) {
             $id = rand(1, 50);
             if (array_search($id, $arrayId) === false) {
                 $arrayId[] = $id;
                 $tagFromBase = $this->getReference("tag {$id}");
                 $article->addTag($tagFromBase);
                 $tagFromBase->getArticles()->add($article);
             }
         }
     }
     $manager->flush();
 }
 /**
  * {@inheritDoc}
  */
 public function getTitle()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getTitle', array());
     return parent::getTitle();
 }