/**
	 * persist an instance of NewsArticle with the entity_manager
	 * 
	 * @param NewsArticle $news
	 */
	public function persist(NewsArticle $news)
	{		
		if(!$news->getPublishedDate()) {
			$news->setPublishedDate(new \DateTime());
		}
		
		$em = $this->getEntityManager();
		$em->persist($news);
	}
Ejemplo n.º 2
0
	public function load($manager)
	{
		for($p = 0; $p < 10; $p++)
		{
			$news = new Entity\NewsArticle();
			$news->setTitle("lôrém news #{$p}");
			$news->setContent("lorem news ipsum #{$p}");
			$inThePast	= rand(0, 100);
			$date		= strtotime("-{$inThePast}days");
			
			$news->setPublishedDate(new \DateTime(date('Y-m-d', $date)));

			$manager->getRepository('GoGreat\CMSBaseBundle\Entity\NewsArticle')->persist($news);				
		}

		$manager->flush();
	}