CI 묻고 답하기

제목 페이지네이션 질문이요 (페이징과 글내용을 한 페이지에..)
글쓴이 wkdwlaks 작성시각 2016/02/03 18:59:27
댓글 : 1 추천 : 0 스크랩 : 0 조회수 : 13793   RSS

코드이그나이터 완전 초보로 공부하고 있는 사람입니다.

 

controller에서 페이지네이션과 글내용을 보는 기능을 각각 구현하고,

view에서 페이지네이션과 글내용을 함께 보여주려고 합니다.

페이지네이션이 포함된 글목록과 글내용 보여주는 페이지를 각각 만들면 문제가 없을 것 같다만,

한 페이지에 같이 보여주려니까 설정을 어떻게 해야할지 모르겠네요.

 

인터넷으로 찾다가 도저히 모르겠어서 결국 만들면서 배우는 코드이그나이터 프레임워크 책도 사서 봤는데,

책에 나온 페이지네이션 부분도 목록과 내용 페이지가 나눠져있는 방법이네요.

 

[ controller 부분 ]

function pagination($id){

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

    $config['total_rows'] = $this->Board_model->gets_count();
    $config['per_page'] = 5;
    $config['use_page_numbers'] = TRUE;
    $config['base_url'] = '/index.php/Board/show/'.$id.'/pagination';
    $this->pagination->initialize($config);

    $pagination = $this->pagination->create_links();

    $page = $this->uri->segment(5, 1);
    if($page > 1){
      $start = ($page/$config['per_page'])*$config['per_page'];
    }else{
      $start = ($page-1)*$config['per_page'];
    }
    $limit = $config['per_page'];

    $topics = $this->Board_model->gets($start,$limit);
    $this->load->view('topic_list',array('topics'=>$topics, 'pagination'=>$pagination));
  }

  function show($id){
    $this->load->view('head');
    $this->Board_model->count($id);         // 조회수
    $topic=$this->Board_model->get($id);
    $this->pagination($id);
    $this->load->view('topic_show',array('topic'=>$topic));
    $this->load->view('footer');
  }

 [ model 부분 ]

function gets_count(){
    return $this->db->query("SELECT * FROM test_table ORDER BY id DESC")->num_rows();
  }

  function gets($offset='',$limit=''){
    return $this->db->query("SELECT * FROM test_table ORDER BY id DESC LIMIT ".$offset.", ".$limit)->result();
  }

  function get($id){
    return $this->db->get_where('test_table',array('id'=>$id))->row();
  }

[ view 목록 부분 ]

<div class="topic_list" align='right'>
  <table border='0' cellspacing='0' cellpadding='0' width='80%' style='TABLE-layout:fixed;'>
    <tr height='1px'><td style="background-color:lightgrey"></td></tr>
    <?php
      foreach($topics as $list){
    ?>
    <tr>
      <td width='90%' align="left" style="border-bottom:1px dotted lightgrey; font-size:10pt; text-overflow:ellipsis; overflow:hidden;">
        <a href="/index.php/Board/show/<?=$list->id?>">  <nobr><?=$list->id?><?=$list->board_title?></nobr>  </a></td>
    </tr>
    <?php
      }
    ?>
    <tr>
      <td align=center><?=$pagination;?></td>
    </tr>
  </table>
  <br><br>
</div>

 

[ view 내용 부분 ]

<table border='0' cellspacing='0' cellpadding='0' width='100%'>

  <tr height="1" bgcolor="lightgrey"><td colspan=3></td></tr>
  <tr height="40"><td align="left" colspan=3> <h3><?=$topic->board_title?></h3> </td></tr>
  <tr height="1" bgcolor="lightgrey"><td colspan=3></td></tr>
  <tr height="30" style="color:grey; font-size:12pt;">
    <td align="left" width="200px"> 작성자 : <?=$topic->board_userid?> </td>
    <td> 작성일시 : <?=$topic->board_date?></td>
    <td align="left" width="150px"> 조회수 : <?=$topic->board_count?></td>
  </tr>
  <tr height="1" bgcolor="lightgrey"><td colspan=3></td></tr>
  <tr height="15"><td colspan=3></td></tr>
  <tr><td style="vertical-align:top;" colspan=3><div align="left">
    <?php
      if($topic->board_file && $topic->board_file != 'no file'){
    ?>
      <img src="/static/img/<?=$topic->board_file?>" style="max-height:500px" /><br />
      <?=nl2br($topic->board_write)?> </div></td></tr>
    <?php
      }else{
    ?>
      <?=nl2br($topic->board_write)?> </div></td></tr>
    <?php
      }
    ?>

  <tr height="15"><td colspan=3></td></tr>
  <tr height="1" bgcolor="lightgrey"><td colspan=3></td></tr>
  <tr height='44'>
    <td colspan=3>
      <form action="" method="post">
        <input type="button" name="" value="수정" onclick="location.href='/index.php/Board/modify/<?=$topic->id?>'">
        <input type="button" name="name" value="삭제" onclick="location.href='/index.php/Board/delete_process/<?=$topic->id?>'">
      </form>
    </td>
  </tr>
  <tr height="1" bgcolor="lightgrey"><td></td></tr>

</table>

 

 다음글 페이지네이션 다시 질문합니다. 꼭 좀 도와주세요
 이전글 새로운 객체 생성은 어떻게 하나요? (6)

댓글

kaido / 2016/02/04 07:17:35 / 추천 0

게시글 불러오는 곳에서 페이지네이션 함수를 호출 하시면 됩니다.

 

model 에 test_table  고정으로 박힌것은  $table 변수 넣고 함수에서 $table 를 인자값으로 넘기면 어느 게시글에서도 원하는 테이블로 페이지네이션이 되겠지요?

 

$pagenation_list  = $this->pagination($id, $table);