Exemplo n.º 1
0
 /**
  * @Route("/getit", name="getit")
  */
 public function getitAction()
 {
     $em = $this->getDoctrine()->getManager();
     $author = $this->get('security.context')->getToken()->getUser();
     $mem_posts = $this->mem->get('posts');
     d($mem_posts);
     return new \Symfony\Component\HttpFoundation\Response('<html><head></head><body>getit</body></html>');
     foreach ($mem_posts as $i => $p) {
         $post = new \Application\Sonata\NewsBundle\Entity\Post();
         $post->setAuthor($author);
         $post->setContentFormatter('richhtml');
         $post->setEnabled(TRUE);
         $post->setCommentsDefaultStatus(1);
         $post->setCreatedAt($p['createdAt']);
         $post->setPublicationDateStart($p['createdAt']);
         $post->setUpdatedAt($p['updatedAt']);
         $post->setTitle($p['title']);
         $post->setContent($p['content']);
         $post->setRawContent($p['content']);
         $post->setAbstract($this->limit_text(strip_tags($p['content']), 15));
         $post->setSlug($p['slug']);
         foreach ($p['tags'] as $tag_name) {
             $post->addTags($this->mergeTag($tag_name));
         }
         $em->getClassMetadata(get_class($post))->setLifecycleCallbacks(array());
         $em->persist($post);
         /* d($i); */
         /*d($post);*/
         /*            
                    if ($i == 1) {
                        break;
                    }
         */
         $em->flush();
     }
     /*
      $post = $this->getDoctrine()
      ->getRepository('ApplicationSonataNewsBundle:Post')
      ->find(1);
     
      d($post);
     */
     return new \Symfony\Component\HttpFoundation\Response('<html><head></head><body>getit</body></html>');
 }