| 제목 | ci 페이지네이션을 통한 페이징처리 | ||
|---|---|---|---|
| 카테고리 | CI 2, 3 | ||
| 글쓴이 | 개멧 | 작성시각 | 2017/06/27 14:46:54 |
|
|
|||
|
안녕하세요. 현재 db에는 10개의 값이 들어가있습니다. 1페이지에 5개 내용물 2페이지에 5개 내용물을 출력하고 싶습니다. $config["total_rows"] 이 부분에 값을 어찌줘야할지 잘 이해가 안갑니다..
아래는 코드 입니다.
컨트롤러
public function listPage()
{
$page = 1;
$listSize = 5;
$oWhere = (object) [
'searchText' => '', //제목 검색
];
$orderBy = 'news.NEWS_SEQ DESC'; //최근등록순
//echo "페이지{$page} 갯수 : {$oResult->totalCount}<br/>";
$data['oResult'] = $this->NewsService->getNewsListPaging($page, $listSize, $oWhere, $orderBy);
$config["base_url"] = base_url() . "/news/listPage";
$config["total_rows"] = ''; //$this->NewsService->getNewsListPaging($totalCount);
$config["per_page"] = 1;
$config['num_links'] = 4;
$config['num_tag_open'] = ' ';
$config['num_tag_close'] = ' ';
$config["euse_query_string"] = true;
$config['full_tag_open'] = '<p>';
$config['first_tag_open'] = ' ';
$config['first_link'] = '<<';
$config['first_tag_close'] = ' ';
$config['prev_tag_open'] = ' ';
$config['prev_link'] = '이전';
$config['prev_tag_close'] = ' ';
$config['next_tag_open'] = ' ';
$config['next_link'] = '다음';
$config['next_tag_close'] = ' ';
$config['last_tag_open'] = ' ';
$config['last_link'] = '>>';
$config['last_tag_close'] = ' ';
$config['full_tag_close'] = '</p>';
$config['use_page_numbers'] = TRUE;
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$this->load->view('news', $data);
}
뷰 <h5><?php echo $pagination; ?></h5>
모델
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class News_service extends CI_Model {
function __construct()
{
parent::__construct();
$this->load->model('News/News_model', 'NewsModel');
}
public function getNewsInfo($newsSeq)
{
$arrWhere = [
'NEWS_SEQ' => $newsSeq,
];
return $this->NewsModel->selectRow($arrWhere);
}
public function getNewsListPaging($page, $listSize, $oWhere, $orderBy)
{
$oLimit = (object) [
'listSize' => $listSize,
'fromNum' => ($page - 1) * $listSize,
];
$totalCount = $this->NewsModel->selectRowTotalCount($oWhere);
return (object) [
'data' => $this->NewsModel->selectListPaging($page, $oLimit, $oWhere, $orderBy),
'totalCount' => $totalCount,
'listNo' => $totalCount - $oLimit->fromNum,
];
}
public function addNewsInfo($oNews)
{
$duplicateString = "
NEWS_TITLE = VALUES(NEWS_TITLE),
NEWS_CNTS = VALUES(NEWS_CNTS),
ALT_USER_NO = VALUES(REG_USER_NO),
ALT_DTTM = VALUES(REG_DTTM)
";
return $this->NewsModel->insertDuplicate($oNews, $duplicateString);
}
public function delNewsInfo($newsSeq)
{
$this->db->trans_start();
$duplicateString = "
NEWS_TITLE = VALUES(NEWS_TITLE),
NEWS_CNTS = VALUES(NEWS_CNTS),
ALT_USER_NO = VALUES(REG_USER_NO),
ALT_DTTM = VALUES(REG_DTTM)
";
return $this->NewsModel->insertDuplicate($oNews, $duplicateString);
$this->db->trans_complete();
}
}
|
|||
| 다음글 | 다른 서버와 통신할때 인증상태 공유하는 방법? (4) | ||
| 이전글 | 파일업로드시 파일이름 암호화가 안되네요. (1) | ||
|
kaido
/
2017/06/27 15:08:47 /
추천
0
|
per_page가 1로 설정 되셨다면...
total_rows = ceil( 전체 개시물 / $listSize)
이런 공식이 됩니다.
사전 조건으로 query 에서 page 숫자 만큼 limit 조건을 주었다면 말이죠.