Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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