Doctrine就是一种对象关系映射(ORM)同时也是一种数据库抽象层(DBAL),使用ORM和DBAL能让我们很轻易的操作数据库。
我们生成了 entity 所以以前我认为entity跟symfony有关,现在看是错的:
$repository = $this->getDoctrine()
->getRepository('AppBundle:Product');
$query = $repository->createQueryBuilder('p')
->where('p.price > :price')
->setParameter('price', '19.99')
->orderBy('p.price', 'ASC')
->getQuery();
$products = $query->getResult();
$configs = $query->getArrayResult();
$repository = $this->getDoctrine()
->getRepository('AppBundle:Worker');
$list= $repository->createQueryBuilder('p')
->where('p.username = :user and p.password=:pss')
->setParameter('user', $user)
->setParameter('pass', md5($pass))
->getQuery();
$list = $list->getSingleResult();