만들면서 배우는 CodeIgniter Q&A

제목 94page 오류 입니다.
글쓴이 프로그래밍좀비 작성시각 2014/11/11 20:28:24
댓글 : 3 추천 : 0 스크랩 : 0 조회수 : 11563   RSS
48번라인 $data('pagination') = $this->pagination->create_links(); 
여기서 계속 에러가 뜹니다. ㅠㅠ



저 부분을 
echo $this->pagination->create_links(); echo를 이용해서 찍어보면

정상적으로 페이지네이션 부분이 출력되는데 앞에 $data변수에 저렇게$data('pagination') 하게되면

위와 같은 에러가 출력됩니다.



Colored By Color Scripter
   
Controller ] board.php
 
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
class Board extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
        $this->load->database();
        $this->load->model('board_m');
        $this->load->helper('date');
    }
 
    public function index()
    {
        $this->lists();
    }
    //_remap모든 메소드에 자동추가 해주는 메소드
    // AJAX를 사용하려면 ajax용 컨트롤러를 따로 만들거나 ajax용 메소드는 메소드명 _ajax로 만들고 _remap()에서 예외처리 한다.
    //사이트 헤더, 푸터가 자동으로 추가 됨.
    public function _remap($method)
    {
        //헤더 include
        $this->load->view('header');
        if(method_exists($this, $method))
        {
            $this->{"{$method}"}();
        }
 
        //푸터 include
        $this->load->view('footer');
    }
 
    function lists()
    {
        //페이지네비게이션 라이브러리 로딩 추가
        $this->load->library('pagination');
 
        // 페이지네이션 설정
        $config['base_url']= '/bbs/index.php/board/lists/ci_board/page/'; // 페이징 주소
        $config['total_rows']=$this->board_m->get_list($this->uri->segment(3), 'count');
        // 게시물의 전체 개수
        $config['per_page']=5;    //한 페이지에 표시할 게시물 수
        $config['uri_segment']=5; // 페이지 번호가 위치한 세그먼트
 
        // 페이지네이션 초기화
        $this->pagination->initialize($config); 
        //페이징 링크를 생성하여 view에서 사용할 변수에 할당
        $data('pagination') = $this->pagination->create_links();
 
        //게시물 목록을 불러오기 위한 offset, limit 값 가져오기
        $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'];
 
        $data['list'] = $this->board_m->get_list($this->uri->segment(3), '', $start, $limit);
        $this->load->view('board/list_v', $data);
    }
}
 
 
 
?>

View ] list_v.php
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
38
39
40
41
42
<article id = "board_area">
    <header>
        <h1></h1>
    </header>
    <table cellspacing= "0" callpadding="0">
        <thead>
            <tr>
                <th scope="col">번호</th>
                <th scope="col">제목</th>
                <th scope="col">작성자</th>
                <th scope="col">조회수</th>
                <th scope="col">작성일</th>
            </tr>
        </thead>
        <tbody>
            <?php 
            foreach ($list as $lt) 
            {
                ?>
                <tr>
                    <th scope="row">
                        <?php echo $lt->board_id;?>
                    </th>
                    <td><a rel="external" href="/bbs/<?php echo $this->uri->segment(1);?>/view/
                        <?php echo $this->uri->segment(3);?>/<?php echo $lt->board_id;?>"><?php echo $lt->subject;?></a></td>
                        <td><?php $lt->user_name?></td>
                        <td><?php $lt->hits?></td>
                        <td><time datetime ="<?php echo mdate("%Y-%M-%j", human_to_unix($lt->reg_date));?>">
                            <?php echo mdate("%Y-%M-%j", human_to_unix($lt->reg_date));?></time></td>
                        </tr>
                        <?php
                    }
                    ?>
 
                </tbody>
                <tfoot>
                    <tr>
                        <th colspan="5"><?php echo $pagination;?></th>                        
                    </tr>
                </tfoot>
                </table>
                </article>

Model ] board_m.php

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
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
class Board_m extends CI_Model
{
    function __construct()
    {
        parent::__construct();
    }
 
    function get_list($table='ci_board', $type='',$offset='',$limit='')
    {
        $limit_query = '';
 
        if($limit != '' OR $offset != '')
        {
            $limit_query = 'LIMIT'.$offset.','.$limit;
        }
        $sql="SELECT * FROM ".$table." ORDER BY board_id DESC".$limit_query;
        $query= $this->db->query($sql);
        if($type == 'count')
        {
            $result = $query->num_rows();
        }
        else
        {
            $result = $query->result();
        }
        return $result;
    }
}
?>


예제가...
초보자 입장에서 아무것도 모르는데 책보며 배우고 있는데.....
오탈자들이 너무많아서 소스 그대로 똑같이 따라했는데 안될때마다 몇시간씩 삽질하고 그러니 힘빠지네요 ㅠㅠ
 다음글 123p 질문있습니다 ! (3)
 이전글 db 로드하는것 질문있습니다 (4)

댓글

프로그래밍좀비 / 2014/11/11 20:34:11 / 추천 0
그리고 추가적으로 82page 예제 그대로 따라치고 오탈자도 봤는데 계속 list_v에서 에러가 출력되서 화면도 이상하고 나오고


<td><time datetime ="<?php echo mdate("%Y-%M-%j", human_to_unix($lt->reg_date));?>">
                            <?php echo mdate("%Y-%M-%j", human_to_unix($lt->reg_date));?></time></td>
                        </tr>
list_v.php 중 위의 부분에서 계속 에러가 떠서 혹시나 하는 마음에..

책에는 Controller에 board.php 소스중 생성자 부분이나 view를 호출하는 메소드가 있는부분에 
$this->load->helper('date'); 이게 없더라구요.. 앞에서도 config/autoload.php에 따로 추가하는 설명도 없고....

이거땜에 6시간넘게 삽질했어요... ㅠㅠ
변종원(웅파) / 2014/11/11 20:48:31 / 추천 0
오탈자 부분은 죄송합니다. 이 게시판에 바로바로 문의하시거나 오탈자 글 참고하세요. 배열에 할당하는걸 잘못하셨네요. $data( 가 아니라 $data[ 입니다. 헬퍼부분도 오탈자에 등록되어 있습니다.
프로그래밍좀비 / 2014/11/11 21:57:39 / 추천 0
아 감사합니다 오탈자 게시판 자주확인하면서 해야겠어요