简体   繁体   中英

Where clause becomes null with pagination in Zend Framework 2

Where clause becomes null when using pagination. ie The first page works fine. But when I click next page 0 results are showing. I debugged by printing the sql statement. The reason for this is 'Where' clause becomes null. Is there any reason for it. How can I resolve this?

    $Sql = new Sql($this->adapter);
    $select = $Sql->select();
    $select->from("TRANSACTION");
    $select->join("vendor","TRANSACTION.vendorID = vendor.vendorID",array('name'));
    $select->where(array('region'=>$region));
    $select->order(array('timestamp DESC'));

    $resultSetPrototype = new ResultSet();
    $paginatorAdapter = new DbSelect($select,$this->getAdapter(),$resultSetPrototype);
    $paginator = new Paginator($paginatorAdapter);
    return $paginator;

This is something i would do to resolve it,

$rows = $Sql->select();
            ->from("TRANSACTION")
            ->join("vendor","TRANSACTION.vendorID = vendor.vendorID",array('name'))
            ->where(array('region'=>$region))
            ->order(array('timestamp DESC'))


$paginator = Zend_Paginator::factory($rows);
$paginator->setItemCountPerPage($this->paginatorNumberPerPage);
$cur_page = isset($data['page']) ? $data['page'] : 0;
$paginator->setCurrentPageNumber($cur_page);
return $paginator;

Where $paginator is returned to the view; and $data['page'] is the page number.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM