Last active
August 29, 2015 14:00
-
-
Save nuxwin/11387884 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In your Module.php file, add the following | |
public function getServiceConfig() | |
{ | |
return array( | |
'factories' => array( | |
'article_mapper' => function ($sm) { | |
return new \Article\Modele\ArticleTable( | |
$sm->get('Doctrine\ORM\EntityManager') | |
); | |
}, | |
), | |
); | |
} | |
# Then, in you controller, you can get the mapper as follow: | |
$articleMapper = $this->getServiceLocator()->get('article_mapper'); | |
$articleMapper->createArticle($data['name'],$data['subject'],$data['email'],$data['message']); | |
# The ArticleTable class become: | |
use Doctrine\ORM\EntityManager as EntityManager; | |
class ArticleTable { | |
protected $em; | |
public function __construct(EntityManager $entityManager) { | |
$this->em = $entityManager; | |
} | |
public function createArticle($name,$subject,$email,$message) | |
{ | |
$article = new ArticlesNew(); | |
$article->setContent($message); | |
$article->setDate(new \DateTime('NOW()')); | |
$article->setIdAuthor($name); | |
$article->setTitle($subject); | |
$this->em->persist( $article); | |
$this->em->flush(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment