I have a read a lot of topics on this and I can\'t seem to find a solution to my problem.
I feel like the problem is obvious and maybe I have just been staring at
One more suggestion: when you are moving database connection out of main controller you need to construct new instance of Entity Manager for instance:
class StoreController extends Controller{
public function addstoreAction(Request $request){
$checkStore = new StoreExistsCheck($this ->getDoctrine()->getManager());
//your code here
}
using /myBundle/Model folder
namespace myBundle\Model;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use myBundle\Entity\Store;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Query;
class StoreExistsCheck extends Controller{
protected $em = null;
protected $kernel = null;
public function __construct(EntityManager $em) {
$this->em = $em;
}
public function storeExists($argosStore){
$storeExists = $this->em ->getRepository('myBundle:Store')
->findOneBystoreNumber($argosStore->getStoreNumber());
return $storeExists;
}