| 제목 | 완전 초보) MVC 질문드립니다! | ||
|---|---|---|---|
| 카테고리 | CI 2, 3 | ||
| 글쓴이 | 베뱁 | 작성시각 | 2017/09/14 17:14:44 |
|
|
|||
|
코드나이터를 써본지 1주일 정도 됐는데요. 게시판 만들기를 해보고 있습니다. view를 로드하면서 db에서 뽑아온 데이터를 배열로 넘겨줬습니다. 궁금한것은 view를 불러오면서 저런 배열값 외의 다른 값들을 전달할 수 있나요?? 페이징 작업을 하면서 토탈 카운트값을 넘기려는데 여러값들을 넘길 수 있는지 궁금합니다.
--controller의 function--
public function blist($page){
$this->_head();
$this->load->helper('url');
$this->load->model('board_model');
if(!$page){
redirect('/board/blist/1');
}
$page_rows = 5;
$st_no = ($page - 1) * $page_rows;
$total_cnt = $this->board_model->b_t_cnt();
$total_page_no = ceil($total_cnt/$page_rows);
if($page > $total_page_no){
redirect('/board/blist/'.$total_page_no);
}
$blist = $this->board_model->board_lists(array(
'st_no'=>$st_no,
'page_rows'=>$page_rows
));
$this->load->view('blist',array('blist'=>$blist));
$this->_footer();
}
--model function--
class Board_model extends CI_Model {
function __construct()
{
parent::__construct();
}
public function upload($option){
//값이 null일때 빈값
foreach($option as $key => $value){
if($option[$key]==null){
$option[$key] = '';
}
$this->db->set($key,$option[$key]);
}
//새글올리기
$this->db->insert('board_table');
//새 글의 아이디 값 리턴
return $this->db->insert_id();
}
public function board_lists($option){
return $this->db->query("SELECT * FROM board_table limit {$option['st_no']}, {$option['page_rows']} ")->result();
}
public function b_t_cnt(){
return $this->db->count_all('board_table');
}
}
--views/blist.php 페이지--
<div class="bs-docs-example">
<table class="table table-striped">
<thead>
<tr>
<th>No</th>
<th>제목</th>
<th>취미</th>
<th>성별</th>
<th>지역</th>
</tr>
</thead>
<tbody>
<?php foreach($blist as $row){?>
<tr>
<td><?php echo $row->id?></td>
<td><?php echo $row->subject;?></td>
<td><?php echo $row->fav1;?> <?php echo $row->fav2;?> <?php echo $row->fav3;?></td>
<td><?php echo $row->sex;?></td>
<td><?php echo $row->area;?></td>
</tr>
<?php }?>
</tbody>
</table>
</div>
<?php echo $total_page_no?> <----여기에 controller에 있는 저 값을 출력하고 싶어요..
|
|||
| 다음글 | post방식으로 받고 데이터베이스에 저장할 때 값 누락 (15) | ||
| 이전글 | ci에서 instance와 static의 의미는... ... (3) | ||
|
변종원(웅파)
/
2017/09/14 17:28:37 /
추천
1
|
|
베뱁
/
2017/09/14 17:44:43 /
추천
0
감사합니다! 정말 간단한 문제인 것을 너무 복잡하게 생각했나봐요 |
매뉴얼을 한번 더 읽어보시면 좋습니다.
배열에 배열과 변수를 담아서 보내면 됩니다.
$data['list'] = array(....);
$data['row'] = 1;
$this->load->view('file', $data);