2017-07-17 68 views
1

我想使用Doctrine Paginator,但是我要使用NativeQuery,因爲我在我的查詢中使用了自定義數據庫函數。NativeQuery的學說分頁器

但我得到這個錯誤:

Fatal error: Uncaught Error: Call to undefined method Doctrine\ORM\NativeQuery::getFirstResult() 

到目前爲止我的代碼是:

$sql = "SELECT std_modulos_aulas.idaula, std_modulos_aulas.idmodulo, conteudo, std_modulos_aulas.titulo 
      FROM uov.std_modulos_aulas 
      INNER JOIN uov.std_modulos ON std_modulos_aulas.idmodulo = std_modulos.idmodulo 
      INNER JOIN uov.std_cursos ON std_cursos.idcurso = std_modulos.idcurso 
      WHERE std_modulos.publicar = 's' AND std_modulos.excluido = 'n' AND std_modulos_aulas.publicar = 's' AND std_cursos.idcurso = ".$curso." AND academico.strip_tags(LOWER(std_modulos_aulas.conteudo)) LIKE '".$termo."' 
      ORDER BY std_modulos.ordem ASC, std_modulos_aulas ASC"; 

$rsm = new ResultSetMapping; 

$rsm->addScalarResult('idaula', 'idaula'); 
$rsm->addScalarResult('idmodulo', 'idmodulo'); 
$rsm->addScalarResult('conteudo', 'conteudo'); 
$rsm->addScalarResult('titulo', 'titulo'); 

$query = $this->em->createNativeQuery($sql, $rsm); 

return new Paginator($query, $fetchJoinCollection = false); 

任何幫助將是很好。我已經嘗試過使用QueryBuilder,但是我的strip_tags函數不能以這種方式工作。舊的話題無法幫助我。

回答

0

對於那些誰可能在未來同樣的問題:

我結束了由解決這個:

在我的模型,我回一個標準的查詢結果:

$sql = "SELECT std_modulos_aulas.idaula, std_modulos_aulas.idmodulo, conteudo, std_modulos_aulas.titulo 
     FROM uov.std_modulos_aulas 
     INNER JOIN uov.std_modulos ON std_modulos_aulas.idmodulo = std_modulos.idmodulo 
     INNER JOIN uov.std_cursos ON std_cursos.idcurso = std_modulos.idcurso 
     WHERE std_modulos.publicar = 's' AND std_modulos.excluido = 'n' AND std_modulos_aulas.publicar = 's' AND std_cursos.idcurso = ".$curso." AND academico.strip_tags(LOWER(std_modulos_aulas.conteudo)) LIKE '".$termo."' 
     ORDER BY std_modulos.ordem ASC, std_modulos_aulas ASC"; 

$rsm = new ResultSetMapping; 

$rsm->addScalarResult('idaula', 'idaula'); 
$rsm->addScalarResult('idmodulo', 'idmodulo'); 
$rsm->addScalarResult('conteudo', 'conteudo'); 
$rsm->addScalarResult('titulo', 'titulo'); 

$query = $this->em->createNativeQuery($sql, $rsm); 
return $query->execute(); 

而且然後,在我的控制器中,我使用了Zend Paginator:

$iteratorAdapter = new \Zend\Paginator\Adapter\ArrayAdapter($result); 
$paginator = new \Zend\Paginator\Paginator($iteratorAdapter); 
$paginator->setCurrentPageNumber($page); 
$paginator->setItemCountPerPage(10);