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

如何使用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.

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