duandong9195 2015-11-06 09:15
浏览 41

左边加入了doctrine orm Zend框架

I have this query below:

SELECT * 
FROM mydb.users
left join mydb.jobs
on users.user_id = jobs.job_id;

And I used to convert them in orm query just like below:

  return 
  $qb = $this->entityManager->createQueryBuilder();
  $qb->select('rb', 'l')
     ->from('Admin\Entity\Users', 'rb')
     ->leftJoin(
        'Admin\Entity\Jobs',
        'l',
        \Doctrine\ORM\Query\Expr\Join::WITH,
        'rb.user_id = l.job_id'
       )
     ->getQuery()
     ->getResult(AbstractQuery::HYDRATE_ARRAY); 

But it doesn's still work. I get the following error:

PHP Fatal error: Call to a member function createQueryBuilder() on null

please help i don't know what to do.

  • 写回答

2条回答 默认 最新

  • dongxiezhi0590 2015-11-06 09:37
    关注

    Try this

    $entityManager = $this->serviceLocator->get('Doctrine\ORM\EntityManager');
    $qb = $entityManager->createQueryBuilder();
    

    Or make sure $this->entityManager is assigned.

    评论

报告相同问题?