티스토리 뷰
728x90
반응형
1.controllers에서 paging 라이브러리를 이용한다
● 페이징 라이브러리를 사용할 컨트롤러 생성
●$this->paging->initPaging을 사용하여 매개변수를 넘김
|
$this->load->library(array('Paging'));
$selects = array('*');
$wheres = array();
$orders = array('code' => 'DESC');
$limit = array('limit' => 5, 'offset' => (5 * ($this->page - 1)));
$data = array();
$data['lists'] = $this->Board_model->lists($selects, $wheres, $orders, $limit);
$data['total'] = $this->Board_model->total($wheres);
$baseUrl = "/admin/board/index?page="; //현재 기본 url
$blockSize = $this->module->board_config->page_count; // 총 블록
$this->paging->initPaging($data['total'], $blockSize, $limit['limit'], $this->page, $baseUrl); //페이징 클래스 호출
$this->paging->getPaging();
|
cs |
2.libraries에서 paging 클래스 생성
|
<?php
if(!defined('BASEPATH')) exit('No direct script access allowed');
Class Paging{
var $total;
var $page;
var $limit;
var $blockSize;
var $baseUrl;
var $limit_start;
var $total_page;
var $total_black;
var $now_block;
var $start_page;
var $end_page;
var $prev_page;
var $next_page;
var $pageString;
function __construct(){
}
function initPaging($total, $blockSize, $limit, $page, $baseUrl){
$this->total = $total; // 총 데이터 수
$this->page = $page; // 현재 페이지
$this->limit = $limit; // 한 페이지 출력 갯수
$this->blockSize = $blockSize; // 한 페이지 블럭 수
$this->baseUrl = $baseUrl; // 기본 URL
$this->total_page = ceil($this->total / $this->limit); // 총 페이지
$this->total_black = ceil($this->total_page / $this->blockSize); // 총 블럭
$this->now_block = ceil($this->page / $this->blockSize); // 현재 페이지의 블럭
$this->start_page = (($this->now_block * $this->blockSize) - ($this->blockSize - 1)); // 가져올 페이지의 시작번호
$this->end_page = ($this->now_block * $this->blockSize); // 가져올 마지막 페이지 번호
$this->prev_page = ($this->now_block * $this->blockSize) - $this->blockSize; // 이전 페이지
$this->next_page = ($this->now_block * $this->blockSize) +1; // 다음 페이지
$this->pageString = '';
}
function getPaging(){
$this->pageString .= "<ul class='pagination'>";
// 이전 페이지
if($this->now_block > 1){
$this->pageString .= "<li class='paginate_button page-item previous' id='dataTable_previous'>";
$this->pageString .= "<a href=".$this->baseUrl.$this->prev_page." aria-controls='dataTable' class='page-link'>Previous</a>";
$this->pageString .= "</li>";
}
// 페이지 리스트
if($this->end_page < $this->total_page):
$end_count = $this->end_page;
else:
$end_count = $this->total_page;
endif;
for($loop = $this->start_page; $loop <= $end_count; $loop++){
$this->pageString .= "<li class='paginate_button page-item active'>";
$this->pageString .= "<a href=".$this->baseUrl.$loop." class='page-link'> $loop </a>";
$this->pageString .= "</li>";
}
// 다음 페이지
if($this->now_block < $this->total_black){
$this->pageString .= "<li class='paginate_button page-item next' id='dataTable_next'>";
$this->pageString .= "<a href=".$this->baseUrl.$this->next_page." aria-controls='dataTable' class='page-link'>Next</a>";
$this->pageString .= "</li>";
}
$this->pageString .= "</ul>";
return $this->pageString;
}
}
?>
|
cs |
3.view에서 paging 호출
1
2
3
4
5
6
7
8
|
<div class="row" style="width: 100%">
<div class="col-sm-4 col-md-4"></div>
<div class="col-sm-4 col-md-4">
<?= $this->paging->pageString; ?>
</div>
<div class="col-sm-4 col-md-4"></div>
</div>
|
cs |
3.결과
728x90
반응형
'PHP > Codeigniter' 카테고리의 다른 글
php - dropzone을 이용한 멀티 업로드 (0) | 2021.01.28 |
---|---|
php - nodejs을 이용한 채팅기능 구현 (5) 전체적인 소스 (0) | 2021.01.28 |
php - nodejs을 이용한 채팅기능 구현 (4) (0) | 2021.01.28 |
php - nodejs을 이용한 채팅기능 구현 (3) (0) | 2021.01.28 |
php - nodejs을 이용한 채팅기능 구현 (2) (0) | 2021.01.28 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- spring boot redisson destributed lock
- transactional outbox pattern spring boot
- spring boot excel download paging
- microkernel architecture
- service based architecture
- spring boot redisson sorted set
- 서비스 기반 아키텍처
- 람다 표현식
- @ControllerAdvice
- 자바 백엔드 개발자 추천 도서
- java userThread와 DaemonThread
- redis sorted set으로 대기열 구현
- 트랜잭셔널 아웃박스 패턴 스프링부트
- transactional outbox pattern
- spring boot 엑셀 다운로드
- 공간 기반 아키텍처
- 레이어드 아키텍처란
- space based architecture
- redis 대기열 구현
- java ThreadLocal
- redis sorted set
- spring boot poi excel download
- pipeline architecture
- JDK Dynamic Proxy와 CGLIB의 차이
- spring boot redisson 분산락 구현
- pipe and filter architecture
- polling publisher spring boot
- spring boot redis 대기열 구현
- spring boot excel download oom
- 트랜잭셔널 아웃박스 패턴 스프링 부트 예제
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
글 보관함