Created
December 15, 2015 22:20
-
-
Save Raistlfiren/8af0fd390b458c3be0b2 to your computer and use it in GitHub Desktop.
Simple Example
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
<?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