page_list.php復(fù)制代碼 代碼如下:<?php if( ! defined('BASEPATH')) die('No Access');/** * 分頁(yè)類 */class Page_list { /** * 總數(shù)據(jù) * @var int */ private $tot " /> 99久久精品6在线播放,爱如潮水3免费观看日本,成人免费视频网站www

天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

codeigniter中測(cè)試通過的分頁(yè)類示例

通用分頁(yè)類(以Codeigniter測(cè)試)

page_list.php
復(fù)制代碼 代碼如下:
<?php if( ! defined('BASEPATH')) die('No Access');

/**
 * 分頁(yè)類
 */
class Page_list {

    /**
     * 總數(shù)據(jù)
     * @var int
     */
    private $total;
    /**
     * 每頁(yè)顯示數(shù)據(jù)
     * @var int
     */
    private $size;
    /**
     * 當(dāng)前頁(yè)數(shù)
     * @var int
     */
    private $page;
    /**
     * 頁(yè)數(shù)列表左右頁(yè)數(shù)
     * @var int
     */
    private $len;

    /**
     * 總頁(yè)數(shù)
     * @var int
     */
    private $page_total;
    /**
     * 頁(yè)碼列表
     * @var array
     */
    private $page_list;

    /**
     * 基準(zhǔn)地址
     * @var string
     */
    private $base_url;
    /**
     * 替換標(biāo)志
     * @var string
     */
    private $place;
    /**
     * 分頁(yè)樣式
     * @var string
     */
    private $style;


    /**
     * 構(gòu)造函數(shù)
     *
     * @param array $config 配置數(shù)組
     */
    public function __construct($config = array()){
        // 初始化默認(rèn)值
        $this->total = 0;
        $this->size = 20;
        $this->page = 1;
        $this->len = 4;
        $this->page_total = 1;
        $this->page_list = array();
        $this->base_url = '?page=-page-';
        $this->place = '-page-';
        $this->style = $this->get_default_style();
        $this->initialize($config);
    }

    /**
     * 初始化分頁(yè)
     *
     * @param array $config 配置數(shù)組
     */
    public function initialize($config = array()){
        // 取得配置值
        if(is_array($config)){
            if(array_key_exists('total', $config)) $this->total = @intval($config['total']);
            if(array_key_exists('size', $config)) $this->size = @intval($config['size']);
            if(array_key_exists('page', $config)) $this->page = @intval($config['page']);
            if(array_key_exists('len', $config)) $this->len = @intval($config['len']);
            if(array_key_exists('base_url', $config)) $this->base_url = @strval($config['base_url']);
            if(array_key_exists('place', $config)) $this->place = @strval($config['place']);
            if(array_key_exists('style', $config)) $this->style = @strval($config['style']);
        }
        // 修正值
        if($this->total<0) $this->total = 0;
        if($this->size<=0) $this->size = 20;
        if($this->page<=0) $this->page = 1;
        if($this->len<=0) $this->len = 4;
        // 執(zhí)行分頁(yè)算法
        $this->page_total = ceil($this->total/$this->size);
        if($this->page_total<=0) $this->page_total = 1;
        if($this->page>$this->page_total) $this->page = $this->page_total;
        if($this->page-$this->len>=1){
            for($i=$this->len; $i>0; $i--){
                $this->page_list[] = $this->page - $i;
            }
        }else{
            for($i=1; $i<$this->page; $i++){
                $this->page_list[] = $i;
            }
        }
        $this->page_list[] = $this->page;
        if($this->page+$this->len<=$this->page_total){
            for($i=1; $i<=$this->len; $i++){
                $this->page_list[] = $this->page + $i;
            }
        }else{
            for($i=$this->page+1; $i<=$this->page_total; $i++){
                $this->page_list[] = $i;
            }
        }
    }

    /**
     * 默認(rèn)分頁(yè)樣式
     *
     * @return string
     */
    public function get_default_style(){
        $style = '<style type="text/css">';
        $style .= ' div.page_list { margin:0;padding:0;overflow:hidden;zoom:1;}';
        $style .= ' div.page_list a {display:block;float:left;height:20px;line-height:21px; font-size:13px;font-weight:normal;font-style:normal;color:#133DB6;text-decoration:none;margin:0 3px;padding:0 7px;overflow;zoom:1;}';
        $style .= ' div.page_list a.page_list_act { font-size:13px;padding:0 6px;}';
        $style .= ' div.page_list a:link, div.page_list a:visited { background:#FFF;border:1px #EEE solid;text-decoration:none;}';
        $style .= ' div.page_list a:hover, div.page_list a:active { background:#EEE;text-decoration:none;}';
        $style .= ' div.page_list strong { display:block;float:left;height:20px;line-height:21px;font-size:13px;font-weight:bold;font-style:normal;color:#000;margin:0 3px;padding:0 8px;overflow:hidden;zoom:1;}';
        $style .= ' </style>';
        return $style;
    }

    /**
     * 是否是第一頁(yè)
     *
     * @return bool
     */
    public function is_first_page(){
        return $this->page == 1;
    }

    /**
     * 獲取第一頁(yè)頁(yè)碼
     *
     * @return int
     */
    public function get_first_page(){
        return 1;
    }

    /**
     * 是否是最后一頁(yè)
     *
     * @return bool
     */
    public function is_last_page(){
        return $this->page == $this->page_total;
    }

    /**
     * 獲取最后一頁(yè)頁(yè)碼
     *
     * @return int
     */
    public function get_last_page(){
        return $this->page_total;
    }

    /**
     * 是否存在
     *
     * @return bool
     */
    public function has_prev_page(){
        return $this->page > 1;
    }

    /**
     * 是否存在
     *
     * @return bool
     */
    public function has_next_page(){
        return $this->page < $this->page_total;
    }

    /**
     * 獲取頁(yè)碼
     *
     * @return int
     */
    public function get_prev_page(){
        return $this->has_prev_page() ? $this->page - 1 : $this->page;
    }

    /**
     * 獲取頁(yè)碼
     *
     * @return int
     */
    public function get_next_page(){
        return $this->has_next_page() ? $this->page + 1 : $this->page;
    }

    /**
     * 獲取當(dāng)前頁(yè)頁(yè)碼
     *
     * @return int
     */
    public function get_curr_page(){
        return $this->page;
    }

    /**
     * 獲取總數(shù)據(jù)數(shù)
     *
     * @return int
     */
    public function get_total(){
        return $this->total;
    }

    /**
     * 獲取每頁(yè)顯示數(shù)據(jù)數(shù)
     *
     * @return int
     */
    public function get_size(){
        return $this->size;
    }

    /**
     * 獲取總頁(yè)數(shù)
     *
     * @return int
     */
    public function get_total_page(){
        return $this->page_total;
    }

    /**
     * 構(gòu)建并返回分頁(yè)代碼
     *
     * @param string $base_url 基準(zhǔn)地址
     * @param string $place 替換標(biāo)志
     * @param string $style 分頁(yè)樣式
     * @return string 分頁(yè)HTML代碼
     */
    public function display($base_url = '', $place = '', $style = ''){
        if($base_url==='') $base_url = $this->base_url;
        if($place==='') $place = $this->place;
        if($style==='') $style = $this->style;
        $str = $style.'<div class="page_list">';
        if( ! $this->is_first_page()){
            $str .= '<a class="page_list_act" href="'.str_replace($place, $this->get_first_page(), $base_url).'">首頁(yè)</a>';
        }
        if($this->has_prev_page()){
            $str .= '<a class="page_list_act" href="'.str_replace($place, $this->get_prev_page(), $base_url).'"></a>';
        }
        foreach($this->page_list as $v){
            if($v==$this->page){
                $str .= '<strong>' . $v . '</strong>';
            }else{
                $str .= '<a href="'.str_replace($place, $v, $base_url).'">'.$v.'</a>';
            }
        }
        if($this->has_next_page()){
            $str .= '<a class="page_list_act" href="'.str_replace($place, $this->get_next_page(), $base_url).'"></a>';
        }
        if( ! $this->is_last_page()){
            $str .= '<a class="page_list_act" href="'.str_replace($place, $this->get_last_page(), $base_url).'">尾頁(yè)</a>';
        }
        $str .= '</div>';
        return $str;
    }

}
?>

/application/view/pagelist.php
復(fù)制代碼 代碼如下:
<?php if( ! defined('BASEPATH')) die('No Access');

    class Pagelist extends CI_Controller {

        public function page(){
            $this->load->helper('url');
            $page = $this->input->get('page');
            $page = @intval($page);
            if($page<=0) $page = 1;
            $this->load->library('page_list',array('total'=>10000,'size'=>16,'page'=>$page));
            $pl = $this->page_list->display(site_url('pagelist/page/page/-page-'));
            $this->load->view('pagelist', array('pl' => $pl));
        }

    }
?>

/application/view/pagelist.php
復(fù)制代碼 代碼如下:
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <title>分頁(yè)測(cè)試</title>
</head>
<body>
<?php echo $pl; ?>
</body>
</html>

php技術(shù)codeigniter中測(cè)試通過的分頁(yè)類示例,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 99久久伊人一区二区yy5o99 | 亚洲欧美日韩精品久久奇米色影视 | 国产精品国产三级国产AV麻豆 | 无码AV熟妇素人内射V在线 | 成人在无码AV在线观看一 | 尤物久久99国产综合精品 | 国产精品女主播主要上线 | 嘿嘿视频在线观看 成人 | 国语对白嫖老妇胖老太 | 97成人精品视频在线播放 | 色 花 堂 永久 网站 | 看全色黄大色大片免费久黄久 | 99国内偷揿国产精品人妻 | 浴室里强摁做开腿呻吟的漫画男男 | 十分钟免费观看大全视频 | 久久香蕉国产线看观看 | 中国字字幕在线播放2019 | 伊人色综合久久天天网 | XXOO麻豆国产在线九九爱 | 在线少女漫画 | 亚洲精品一本之道高清乱码 | 亚洲精品一二三区-久久 | 精品久久日日躁夜夜躁AV | jjzz动漫| 青柠电影在线看 | 国色精品VA在线观看免费视频 | 忘忧草研究院一二三 | 久久久久久人精品免费费看 | 在线观看免费视频播放视频 | 国产精品久久人妻无码网站一区L | 最近中文字幕MV高清在线视频 | 羽月希被黑人吃奶dasd585 | 免费精品一区二区三区在线观看 | 日本XXXXZZX片免费观看 | 美女露100%全身无遮挡 | 中文字幕亚洲乱码熟女在线 | 黑丝袜论坛 | 99精品视频免费在线观看 | 久久婷婷国产五月综合色啪最新 | 国产精品人妻久久无码不卡 | 国内精品久久久久久久999下 |