Zend Paginator displays the wrong page count when the request is "excellent"

I use Zf 1.10 in the project and very successfully used Zend_Paginator along with Zend_DbTable requests before this bit.

The query requires the DISTINCT keyword to remove duplicate rows created by the join, but when I add it, the paginator does not display the navigation correctly for two result pages when there is only one result page. Some digging shows that he performs two queries, one for the result set that I followed (77 lines), and the other to get the score. But the second query created by Zend magic does not include the DISTINCT keyword, so the counter returns 112 lines instead of 77 lines.

Here is the corresponding bit

$select = $this->select()
    ->setIntegrityCheck(false)
    ->from('companies')
    ->distinct()
    ->join('project_team', 'companies.companyID = project_team.companyID', null)
    ->join('project_team_roles', 'project_team.roleID = project_team_roles.roleID', null)
    ->join('projects', 'projects.projectID = project_team.projectID', null)
    ->where('project_team_roles.isArchitect')
    ->where('companies.companyName LIKE ?', '%' . $str . '%')
    ->where('projects.islive AND NOT projects.isDeleted')
    ->order('companies.companyName'); 
 $adapter = new Zend_Paginator_Adapter_DbTableSelect($select);
 $paginator = new Zend_Paginator($adapter);
 $paginator->setCurrentPageNumber($page);
 $paginator->setItemCountPerPage(100);
 return $paginator;

, , , DISTINCT count. → distinct(), - 112 , , .

, , ZF

? ? -, , . , , , .

Ian

EDIT - , .

+3
2

, .

setRowCount() .

$select = $your_model->getSelect();
$select_count = $your_model->getCount(); // geting count from select above
$adapter = new Zend_Paginator_Adapter_DbSelect($select);
$adapter->setRowCount((int)trim($select_count)); // <-- // set integer !
$paginator = new Zend_Paginator($adapter);
// That it
...

$this->view->paginator = $paginator; 
// and so on...
+2

... DbTable, , paginator

$results = $this->fetchAll($select)->toArray(); 
$adapter = new Zend_Paginator_Adapter_Array($results);

DbTable, .

!

0

Source: https://habr.com/ru/post/1768754/


All Articles