使用带有Doctrine paginator的Doctrine 2执行原始SQL

时间:2017-12-14 08:11:29

标签: php symfony doctrine-orm

我正在尝试进行分页,但是有一个错误:

$dql = "SELECT cast(ip as CHAR) as ip FROM histories";
$query = $em->createQuery($dql)->setFirstResult($offset)->setMaxResults($limit); 
$paginator = new Paginator($query);  
$maxpage = ceil($paginator->count() / $limit);

错误

  

[语法错误]第0行,第7行:错误:预期的IdentificationVariable |   ScalarExpression | AggregateExpression |功能声明|   PartialObjectExpression | “(”Subselect“)”| CaseExpression,获得'*'

     

$ maxpage = ceil($ paginator-> count()/ $ limit); //错误行

1 个答案:

答案 0 :(得分:1)

请尝试:

$maxpage = ceil(count($paginator) / $limit);

Read the doc