FatalErrorException: Error: Call to a member function has() on a non-object

后端 未结 3 1715
感情败类
感情败类 2020-12-16 05:01

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

3条回答
  •  时光取名叫无心
    2020-12-16 05:13

    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;
    
    } 
    

提交回复
热议问题