Skip to content

Instantly share code, notes, and snippets.

@Raistlfiren
Created December 15, 2015 22:20
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 Raistlfiren/8af0fd390b458c3be0b2 to your computer and use it in GitHub Desktop.
Save Raistlfiren/8af0fd390b458c3be0b2 to your computer and use it in GitHub Desktop.
Simple Example
<?php
use Doctrine\Common\Persistence\ObjectManager;
class Lead
{
protected $POST_Data;
protected $_em;
public function __construct(ObjectManager $em) {
$this->_em = $em;
}
public function hasLegalFields()
{
$legalFields = $this->getLeadFields();
//Compare $POST_Data against the $legalFields array
foreach ($POST_Data as $key => $value) {
if ($key if in $legalFields array) {
//do nothing
} else {
unset($POST_Data[$key];
}
}
}
public function getLeadFields()
{
$repository = $this->_em->getDoctrine()
->getRepository('AppBundle:LeadFields');
$leadFields = $repository->findAll();
//process these objects into an array containing ONLY the leadField attribute and return it.
}
}
services.yml
services:
lead_bundle.lead:
class: LeadBundle\Lead
arguments: [@doctrine.orm.entity_manager]
tags:
- { name: kernel.event_subscriber }
//Class can be accessed like this in your controller or wherever your container is injected at
$this->get('lead_bundle.lead')->hasLegalFields()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment