Zend Framework框架实现类似Google搜索分页效果

乐观主义者从每一个灾难中看到机遇,而悲观主义都从每一个机遇中看到灾难。无论有多困难,都坚强地抬头挺胸,人生是一场醒悟,不要昨日,不要明天,只要今日。

本文实例讲述了Zend Framework框架实现类似Google搜索分页效果。分享给大家供大家参考,具体如下:

/**
*
* @param unknown_type $model 表类型
* @param unknown_type $ncontroller 那个控制器提交的controller
* @param unknown_type $naction 那个action提交的action
*/
public function fenyepage2($model,$ncontroller,$naction){
    if(!isset($_SESSION))
    {session_start();}
    $pageSize = $_SESSION['pagesize'];
    $pageNow = $_SESSION['pagenow'];
    $offset = ($pageNow-1)*$pageSize;
    $db = $this->getAdapter();
    $select = $db->select();
    $select->from('student','*');
    if(!isset($_SESSION))
    {session_start();}
    if($_SESSION['qsname']!=""){
      $sname = $_SESSION['qsname'];
      $select->where('sname like ?',"%$sname%");
    }
    if($_SESSION['qsaddress']!=""){
      $saddress = $_SESSION['qsaddress'];
      $select->where('saddress like ?',"%$saddress%");
    }
    if($_SESSION['qsdept']!=""){
      $sdept = $_SESSION['qsdept'];
      $select->where('sdept like ?',"%$sdept%");
    }
    $coutNews = $db->fetchAll($select);
    $pageCount = ceil(count($coutNews)/$pageSize);
    $select->limit($pageSize,$offset);//第一个参数:总共显示多少个。第二个参数:从第几个开始显示
    $res = $db->fetchAll($select);
    $native = null;
    $native = "<a rel="nofollow noopener noreferrer" href='\\$ncontroller\\$naction?pageNow=1&pagesize=$pageSize'>首页</a> ";
    if($pageNow>1){
      $nextPage = $pageNow-1;
      $native.="<a rel="nofollow noopener noreferrer" href='\\$ncontroller\\$naction?pageNow=$nextPage&pagesize=$pageSize'>上一页</a>";
    }
      if(($pageNow-1)>5){
        if($pageNow+4>$pageCount){//如果最后的页数和理应前面开始的页数小于10则
          $start = $pageCount-9;//开始的页数和结束的页数相差9
        }else{
          $start=$pageNow-5;//开始位置和结束位置相差5
        }
      }else{
        $start = floor(($pageNow-1)/10)*10+1;
      }
      if($pageCount>=$start+10){
        $index = $start+10;
      }
      else{
        $index = $pageCount+1;
      }
      for(;$start<$index;$start++){
        $native.="<a rel="nofollow noopener noreferrer" href='\\$ncontroller\\$naction?pageNow=$start&pagesize=$pageSize'>$start</a>";
      }
    if($pageNow<$pageCount){
      $nextPage = $pageNow+1;
      $native.="<a rel="nofollow noopener noreferrer" href='\\$ncontroller\\$naction?pageNow=$nextPage&pagesize=$pageSize'>下一页</a>";
    }
    $native.="<a rel="nofollow noopener noreferrer" href='\\$ncontroller\\$naction?pageNow=$pageCount&pagesize=$pageSize'>末页</a>";
    $native.="当前{$pageNow}||总共{$pageCount}页";
    $model->arrs = $res;
    $model->native = $native;
}

希望本文所述对大家基于Zend Framework框架的PHP程序设计有所帮助。

以上就是Zend Framework框架实现类似Google搜索分页效果。一天要做三件事,第一要笑,第二要微笑,第三要哈哈大笑。更多关于Zend Framework框架实现类似Google搜索分页效果请关注haodaima.com其它相关文章!

标签: 分页 Zend