带有代码:
$qb = $entityManager->createQueryBuilder();
$qb->select('cat')->from('BuyAndSellSiteBundle:Category ', 'cat');
$qb->getQuery();
$a =$qb->getResult();
我有一个异常(exception):
FatalErrorException: Error: Call to undefined method Doctrine\ORM\QueryBuilder::getResult() in C:\xampp\htdocs\buySell\src\BuyAndSell\SiteBundle\Controller\DefaultController.php line
最佳答案
这是有道理的。因为QueryBuilder
本身不会改变,所以您需要存储getQuery()
调用的结果:
$queryBuilder = $entityManager->createQueryBuilder();
$queryBuilder->select('cat')->from('BuyAndSellSiteBundle:Category ', 'cat');
// get the Query from the QueryBuilder here ...
$query = $qb->getQuery();
// ... then call getResult() on the Query (not on the QueryBuilder)
$result = $query->getResult();
关于php - Symfony2:调用未定义的方法Doctrine\ORM\QueryBuilder::getResult(),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21222946/