婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁(yè) > 知識(shí)庫(kù) > CI框架簡(jiǎn)單分頁(yè)類(lèi)用法示例

CI框架簡(jiǎn)單分頁(yè)類(lèi)用法示例

熱門(mén)標(biāo)簽:如何在世界地圖標(biāo)注 電子地圖標(biāo)注怎么修改 公司外呼系統(tǒng)中心 菏澤語(yǔ)音外呼系統(tǒng)運(yùn)營(yíng)商 廈門(mén)400電話辦理選易號(hào)網(wǎng) 天客通地圖標(biāo)注 臨沂crm外呼系統(tǒng)平臺(tái) 地圖標(biāo)注符號(hào)樣式有 梧州市機(jī)器人外呼系統(tǒng)怎么樣

本文實(shí)例講述了CI框架簡(jiǎn)單分頁(yè)類(lèi)用法。分享給大家供大家參考,具體如下:

/** 
 * 
 * 關(guān)于 頁(yè)碼有效性的判斷需要加在 控制器中判斷,即當(dāng)頁(yè)碼數(shù)1或者>總頁(yè)數(shù) 
 * 
 */ 
class Custom_pagination 
{ 
  var $page_url = ''; //分頁(yè)目標(biāo)URL 
  var $page_size = 10; //每一頁(yè)行數(shù) 
  var $page_num = 1;//頁(yè)碼 
  var $rows_num= '';//數(shù)據(jù)總行數(shù) 
  var $links_num= 3;//選中鏈接前后的鏈接數(shù),必須大于等于1 
 
  var $anchor_class= '';//鏈接樣式類(lèi) 
  var $current_class= '';//當(dāng)前頁(yè)樣式類(lèi) 
  var $full_tag_open= '';//分頁(yè)開(kāi)始標(biāo)簽 
  var $full_tag_close= '';//分頁(yè)結(jié)束標(biāo)簽 
  var $info_tag_open= ''; 
  var $info_tag_close= ' '; 
  var $first_tag_open= ''; 
  var $first_tag_close= ' '; 
  var $last_tag_open= ' '; 
  var $last_tag_close= ''; 
  var $cur_tag_open= ' strong>'; 
  var $cur_tag_close= '/strong>'; 
  var $next_tag_open= ' '; 
  var $next_tag_close= ' '; 
  var $prev_tag_open= ' '; 
  var $prev_tag_close= ''; 
  var $num_tag_open= ' '; 
  var $num_tag_close= ''; 
 
  public function __construct($params = array()) 
  { 
    if (count($params) > 0) 
    { 
      $this->init($params); 
    } 
  } 
  
  function init($params = array()) //初始化數(shù)據(jù) 
  { 
    if (count($params) > 0) 
    { 
      foreach ($params as $key => $val) 
      { 
        if (isset($this->$key)) 
        { 
          $this->$key = $val; 
        } 
      } 
    } 
  } 
  
  function create_links() 
  { 
    /////////////////////////////////////////////////////// 
    //準(zhǔn)備數(shù)據(jù) 
    /////////////////////////////////////////////////////// 
    $page_url = $this->page_url; 
    $rows_num = $this->rows_num; 
    $page_size = $this->page_size; 
    $links_num = $this->links_num; 
 
    if ($rows_num == 0 OR $page_size == 0) 
    { 
      return ''; 
    } 
 
    $pages = intval($rows_num/$page_size); 
    if ($rows_num % $page_size) 
    { 
      //有余數(shù)pages+1 
      $pages++; 
    }; 
    $page_num = $this->page_num  1 ? '1' : $this->page_num; 
 
    $anchor_class = ''; 
    if($this->anchor_class !== '') 
    { 
      $anchor_class = 'class="'.$this->anchor_class.'" '; 
    } 
 
    $current_class = ''; 
    if($this->current_class !== '') 
    { 
      $current_class = 'class="'.$this->current_class.'" '; 
    } 
    if($pages == 1) 
    { 
      return ''; 
    } 
    if($links_num  0) 
    { 
      return '- -!links_num必須大于等于0'; 
    } 
    //////////////////////////////////////////////////////// 
    //創(chuàng)建鏈接開(kāi)始 
    //////////////////////////////////////////////////////// 
    $output = $this->full_tag_open; 
    $output .= $this->info_tag_open.'共'.$rows_num.'條數(shù)據(jù) 第 '.$page_num.'/'.$pages.' 頁(yè)'.$this->info_tag_close; 
    //首頁(yè) 
    if($page_num > 1) 
    { 
      $output .= $this->first_tag_open.'a '.$anchor_class.' href="'.site_url($page_url).'" rel="external nofollow" >首頁(yè)/a>'.$this->first_tag_close; 
    } 
    //上一頁(yè) 
    if($page_num > 1) 
    { 
      $n = $page_num - 1; 
      $output .= $this->prev_tag_open.'a '.$anchor_class.' href="'.site_url($page_url.'/'.$n).'" rel="external nofollow" rel="external nofollow" >上一頁(yè)/a>'.$this->prev_tag_close; 
    } 
    //pages 
    for($i=1;$i=$pages;$i++) 
    { 
      $pl = $page_num - $links_num  0 ? 0 : $page_num - $links_num; 
      $pr = $page_num + $links_num > $pages ? $pages : $page_num + $links_num; 
      //判斷鏈接個(gè)數(shù)是否太少,舉例,假設(shè)links_num = 2,則鏈接個(gè)數(shù)不可少于 5 個(gè),主要是 當(dāng)page_num 等于 1, 2 和 n,n-1的時(shí)候 
      if($pr  2 * $links_num + 1) 
      { 
        $pr = 2 * $links_num + 1; 
      } 
      if($pl > $pages-2 * $links_num) 
      { 
        $pl = $pages - 2 * $links_num; 
      } 
      if($i == $page_num) 
      {  //current page 
        $output .= $this->cur_tag_open.'span '.$current_class.' >'.$i.'/span>'.$this->cur_tag_close; 
      }else if($i >= $pl  $i = $pr) 
      { 
        $output .= $this->num_tag_open.'a '.$anchor_class.' href="'.site_url($page_url.'/'.$i).'" rel="external nofollow" >'.$i.'/a>'.$this->num_tag_close; 
      } 
    } 
    //下一頁(yè) 
    if($page_num  $pages) 
    { 
      $n = $page_num + 1; 
      $output .= $this->next_tag_open.'a '.$anchor_class.' href="'.site_url($page_url.'/'.$n).'" rel="external nofollow" rel="external nofollow" >下一頁(yè)/a>'.$this->next_tag_close; 
    } 
    //末頁(yè) 
    if($page_num  $pages) 
    { 
      $output .= $this->last_tag_open.'a '.$anchor_class.' href="'.site_url($page_url.'/'.$pages).'" rel="external nofollow" >末頁(yè)/a>'.$this->last_tag_close; 
    } 
 
    $output.=$this->full_tag_close; 
    return $output; 
  } 
} 

控制器里調(diào)用

$config['page_url'] 
= 'about/science'; 
$config['page_size'] = $pagesize; 
$config['rows_num'] = $num_rows; 
$config['page_num'] = $page; 
$this->load->library('Custom_pagination'); 
$this->custom_pagination->init($config); 
echo $this->custom_pagination->create_links(); 

?php 
class page{ 
   
  public $page; //當(dāng)前頁(yè) 
  public $pagenum; // 頁(yè)數(shù) 
  public $pagesize; // 每頁(yè)顯示條數(shù) 
  public function __construct($count, $pagesize){ 
    $this->pagenum = ceil($count/$pagesize); 
    $this->pagesize = $pagesize; 
    $this->page =(isset($_GET['p'])$_GET['p']>0) ? intval($_GET['p']) : 1; 
  } 
  /** 
   * 獲得 url 后面GET傳遞的參數(shù) 
   */  
  public function getUrl(){   
    $url = 'index.php?'.http_build_query($_GET); 
    $url = preg_replace('/[?,]p=(\w)+/','',$url); 
    $url .= (strpos($url,"?") === false) ? '?' : ''; 
    return $url; 
  } 
  /** 
   * 獲得分頁(yè)HTML 
   */ 
  public function getPage(){ 
    $url = $this->getUrl(); 
    $start = $this->page-5; 
    $start=$start>0 ? $start : 1;  
    $end  = $start+9; 
    $end = $end$this->pagenum ? $end : $this->pagenum; 
    $pagestr = ''; 
    if($this->page>5){ 
      $pagestr = "a href=".$url." rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" p=1".">首頁(yè)/a> "; 
    } 
    if($this->page!=1){ 
      $pagestr.= "a href=".$url." rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" p=".($this->page-1).">上一頁(yè)/a>"; 
    } 
     
    for($i=$start;$i=$end;$i++){ 
      $pagestr.= "a href=".$url." rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" p=".$i.">".$i."/a> ";            
    } 
    if($this->page!=$this->pagenum){ 
      $pagestr.="a href=".$url." rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" p=".($this->page+1).">下一頁(yè)/a>"; 
       
    } 
    if($this->page+5$this->pagenum){ 
      $pagestr.="a href=".$url." rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" p=".$this->pagenum.">尾頁(yè)/a> "; 
    } 
    return $pagestr;   
  } 
   
} 
// 測(cè)試代碼 
$page = new page(100,10); 
$str=$page->getPage(); 
echo $str; 
?>

更多關(guān)于CodeIgniter相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《codeigniter入門(mén)教程》、《CI(CodeIgniter)框架進(jìn)階教程》、《php優(yōu)秀開(kāi)發(fā)框架總結(jié)》、《ThinkPHP入門(mén)教程》、《ThinkPHP常用方法總結(jié)》、《Zend FrameWork框架入門(mén)教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門(mén)教程》、《php+mysql數(shù)據(jù)庫(kù)操作入門(mén)教程》及《php常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總》

希望本文所述對(duì)大家基于CodeIgniter框架的PHP程序設(shè)計(jì)有所幫助。

您可能感興趣的文章:
  • CI框架常用經(jīng)典操作類(lèi)總結(jié)(路由,偽靜態(tài),分頁(yè),session,驗(yàn)證碼等)
  • CI框架(ajax分頁(yè),全選,反選,不選,批量刪除)完整代碼詳解
  • Codeigniter(CI)框架分頁(yè)函數(shù)及相關(guān)知識(shí)
  • PHP CodeIgniter分頁(yè)實(shí)例及多條件查詢解決方案(推薦)
  • CodeIgniter分頁(yè)類(lèi)pagination使用方法示例
  • codeigniter實(shí)現(xiàn)get分頁(yè)的方法
  • Codeigniter框架實(shí)現(xiàn)獲取分頁(yè)數(shù)據(jù)和總條數(shù)的方法
  • codeigniter中測(cè)試通過(guò)的分頁(yè)類(lèi)示例

標(biāo)簽:黃石 瀘州 綿陽(yáng) 迪慶 郴州 貴陽(yáng) 白城 雞西

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《CI框架簡(jiǎn)單分頁(yè)類(lèi)用法示例》,本文關(guān)鍵詞  框架,簡(jiǎn)單,分頁(yè),類(lèi),用法,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《CI框架簡(jiǎn)單分頁(yè)類(lèi)用法示例》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于CI框架簡(jiǎn)單分頁(yè)類(lèi)用法示例的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 紫金县| 兴安县| 西充县| 汶上县| 临西县| 绩溪县| 宝清县| 临漳县| 合水县| 大城县| 垣曲县| 巴彦淖尔市| 绩溪县| 南昌市| 榆树市| 淄博市| 铜鼓县| 曲沃县| 博湖县| 噶尔县| 江达县| 霞浦县| 开江县| 中牟县| 嘉荫县| 元氏县| 吉安县| 岳池县| 石柱| 抚松县| 清丰县| 永平县| 亳州市| 罗田县| 塔城市| 琼海市| 鲜城| 吴忠市| 秦皇岛市| 秦安县| 永胜县|