Skip to content

Instantly share code, notes, and snippets.

@nuxwin
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nuxwin/11387884 to your computer and use it in GitHub Desktop.
Save nuxwin/11387884 to your computer and use it in GitHub Desktop.
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