【发布时间】:2015-02-28 21:55:59
【问题描述】:
您好,我正在使用 Symfony 2.4 进行项目,我想使用 QueryBuilder 进行选择,但我有一个例外:
FatalErrorException:错误:调用未定义的方法 getEntityManager() 这是我的代码:
$session=$this->get('session');
$id_client=$session->get('client');
$emConfig = $this->getEntityManager()->getConfiguration();
$emConfig->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\Query\Mysql\Year');
$qb = $this->createQueryBuilder('f');
$qb->select('SUM(f.montantTtc)');
$qb->from('factureBundle:Facture', 'f');
$qb->where('f.client = :id_client');
$qb->groupBy('YEAR(f.dateEdition)');
$qb->setParameter('id_client', $id_client);
$factures_by_years=$qb->getQuery()->getResult();
请帮帮我
【问题讨论】:
-
你能发布完整的类定义吗?我认为这个类中没有
getEntityManager方法 -
我打赌你在控制器里:
$em = $this->get('doctrine.orm.entity_manager')
标签: php symfony doctrine-orm