drzfnr0275 2013-11-17 05:01
浏览 79
已采纳

如何使用doctrine从Symfony2中的数据库表中获取值列表?

I am new to symfony2 and doctrine. I need to know how to get the complete list from a table using a doctrine command. getDoctrine()->getManager()->getRepository('bundeName')->findOneBy() gets only one value based on a criteria. Hope I'm making sense. Please help. Thank you.

  • 写回答

1条回答 默认 最新

  • doutian4046 2013-11-17 05:15
    关注

    Try something like:

    $repositorySites = $this->getDoctrine()->getRepository('SomeBundle:Sites');
    $sites           = $repositorySites->findAll();
    

    This might help to filter (put in the class repo):

    class SitesRepository extends EntityRepository
    {
        public function findByNot($field, $value)
        {
            $qb = $this->createQueryBuilder('a');
            $qb->where($qb->expr()->not($qb->expr()->eq('a.'.$field, '?1')));
            $qb->setParameter(1, $value);
    
            return $qb->getQuery()
                ->getResult();
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?