CI 묻고 답하기

제목 pagination 부분이 잘 되지 않습니다.
글쓴이 overman623 작성시각 2016/02/29 15:28:23
댓글 : 6 추천 : 0 스크랩 : 0 조회수 : 17484   RSS
------controller--------

function boardLists(){

$this->load->library('pagination');

$config['base_url'] = '/kim/main/boardLists/page';

$config['total_rows'] = $this->board_m->getListsCount();

$config['per_page'] = 5;

$config['uri_segment'] = 5;

$this->pagination->initialize($config);

$page = $this->uri->segment(4, 1);

error('page : '. $page);

$data['pagination'] = $this->pagination->create_links();

if ($page > 1) $startBoardNum = ($page/$config['per_page']) * $config['per_page'];

else $startBoardNum = ($page - 1) * $config['per_page'];

$data['lists'] = $this->board_m->getLists($startBoardNum, 5);

$this->load->view('section/board/list_v', $data);

}

 

------ㅡmodel--------

function getListsCount(){

$sql = "SELECT COUNT(*) as cnt FROM ".NOWTABLE;

$row = $this->db->query($sql);

$result = $row->row_array();

return $result['cnt'];

}

function getLists($start, $offset){

$sql = "SELECT * FROM ".NOWTABLE." LIMIT ".$start."," .$offset.";";

error('test sql : '. $sql);

$query = $this->db->query($sql);

return $query->result();

}

------ㅡview--------

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

32

33

34

35

36

37

    <content>

      <table class="table table-striped">

        <thead>

          <tr>

            <th>번호</th>

            <th>제목</th>

            <th>작성자</th>

            <th>조회수</th>

            <th>작성일</th>

          </tr>

        </thead>

        <tbody>

<?php 

foreach($lists as $lt)

{?>

          <tr>

            <td><?php echo $lt->board_id?></td>

            <td><a href="/kim/main/boardListDetail/<?php echo $lt->board_id?>"><?php echo $lt->subject?></a></td>

            <td><?php echo $lt->user_name?></td>

            <td><?php echo $lt->hits?></td>

            <td><time datetime="<?php echo mdate("%M. %j, %Y", human_to_unix($lt->reg_date))?>">

              <?php echo mdate("%M. %j, %Y", human_to_unix($lt->reg_date))?></time></td>

          </tr>

<?php

}

?>

        </tbody>

        

        <tfoot>

            <tr>

                <th colspan="5"><?php echo $pagination; /*error($pagination)*/?></th>

            </tr>

        </tfoot>

      </table>

      <button name="button1id" class="btn btn-success" onclick="location.href = '/kim/main/writeHandler'">글쓰기</button>

    </content>

  </div>

Colored by Color Scripter

cs

처음 사진을 보시게되면 2페이지로 가는 링크를 누른후에도 페이지만 이동하지 페이지네이션 부분은 변하지 않는 현상이 일어났습니다. 교재를 참고하면서 입력했는데 어느 부분이 잘못된지 몰라서 질문 올립니다. 필요한 정보가 있다면 더 쓰도록 하겠습니다.

 다음글 [질문] url 관련 (5)
 이전글 ci 쿠키 질문입니다. (3)

댓글

변종원(웅파) / 2016/02/29 15:45:09 / 추천 0
$page = $this->uri->segment(4, 1); <- 5번째 세그먼트가 페이징변수입니다.
overman623 / 2016/02/29 17:14:57 / 추천 0
그곳을 변경해야 한다는 말씀이십니까???
변종원(웅파) / 2016/02/29 18:15:52 / 추천 0

echo $page; 해보세요. 화면에 page라고 출력됩니다.

해당 내용은 현재 페이지가 몇 페이지인지 그 내용을 주소에서 가져오는건데 4번째 세그먼트를 가져오는게 아니라 5번째를 가져와야 합니다.

overman623 / 2016/02/29 18:26:52 / 추천 0

우연히도 $config['uri_segment'] = 5; 에서 4로 고쳤더니 변화가 생겼습니다.

교재에서는 페이지 번호가 위치한 세그먼트라는 쓰여있는데, 제가 잘 이해를 못했나 봅니다.

사실 지금 하는 연습에서는 uri에 index.php글자를 생략하는 실습을 마친 상태입니다.

그러니까 4번째 세그먼트에 있는 값을 가져와야 하는데 5번째 값을 가져온 것인거 같습니다.

정확한 숫자를 가져오지 않으면 발생하는 문제였나요??

변종원(웅파) / 2016/02/29 18:33:07 / 추천 0

index.php가 0번째 세그먼트입니다. kim이 첫번째 세그먼트가 되구요.

책 = 매뉴얼이 아니기 때문에 매뉴얼도 필독하셔야 합니다. 책의 아까운 공간에 매뉴얼을 그대로 싣는 것은 낭비라고 생각되어서

필요한 부분 아니면 넣지 않았습니다.

overman623 / 2016/02/29 18:57:50 / 추천 0
네 알겠습니다. 답변 감사합니다.