CI 묻고 답하기

제목 안녕하세요 질문 있습니다 ㅠ
글쓴이 trace 작성시각 2016/09/04 02:14:18
댓글 : 5 추천 : 0 스크랩 : 0 조회수 : 19475   RSS

안녕하세요 모델에서 board라는 db에 user_id 값이 특정 값인 row 갯수를 구하고 그것을 controller에서 쓰려고 합니다. 다음 과 같이 구문을 작성하였는데, controller에서 model에 작성한 function이 안불러와져서 제가 뭘 잘못했는지 도저히 모르겠습니다. ㅠㅠ

[ ▼ 질문관련 참고 Source ]

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

//model내용//

public function get_num_row($user_id='')

    {

         

    $this->db->select('mem_id');

    $this->db->where('mem_id',$user_id);

    $query = $this->db->get('board');

    $num = $query->num_rows();

    return $num;

 

    }

 

//controller 내용//

$user_id= $this->member->is_member();

$num_board = $this->Board_model->get_num_row($user_id);

 다음글 안녕하세요 질문 있습니다. ㅠ (2)
 이전글 켈린더라이브러리 템플릿 관련 질문드려요 (1)

댓글

배강민 / 2016/09/04 09:46:23 / 추천 0

Board_model 은 어떻게 불러오셨나요? get_num_row 메쏘드가 Board_model 클래스에 있는건 맞나요?

말씀하신데로 "메쏘드"가 아예 안불러와지는거라면, 이렇게 해당 메쏘드 내용과, 그 부분을 호출 하는 것만으로는 알 수가 없습니다.

trace / 2016/09/04 10:40:45 / 추천 0

@배강민 먼저 댓글 감사합니다.

Board_model을 불러오는건 15번 줄에 있는 $this->Board_model->get_num_row($user_id); 이 구문이 아닌가요 ㅠ

get_num_row function은 Board_model에 있는 것 확실합니다. 그리고 Board_model 에 있는 다른 function들은 되는데 이것만 안되서 혹시 제가 잘못 친게 있나 싶어서요 ㅠ

trace / 2016/09/04 10:42:33 / 추천 0

Board_model의 전체 구문입니다.

 

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * Board model class
 *
 * Copyright (c) CIBoard <www.ciboard.co.kr>
 *
 * @author CIBoard (develop@ciboard.co.kr)
 */

class Board_model extends CB_Model
{

    /**
     * 테이블명
     */
    public $_table = 'board';

    /**
     * 사용되는 테이블의 프라이머리키
     */
    public $primary_key = 'brd_id'; // 사용되는 테이블의 프라이머리키

    public $cache_prefix = 'board/board-model-get-'; // 캐시 사용시 프리픽스

    public $cache_time = 86400; // 캐시 저장시간

    function __construct()
    {
        parent::__construct();

        check_cache_dir('board');
    }


    public function get_admin_list($limit = '', $offset = '', $where = '', $like = '', $findex = '', $forder = '', $sfield = '', $skeyword = '', $sop = 'OR')
    {
        $result = $this->_get_list_common($select = '', $join = '', $limit, $offset, $where, $like, $findex, $forder, $sfield, $skeyword, $sop);
        return $result;
    }


    public function get_board_list($where = '')
    {
        $result = $this->get('', '', $where, '', 0, 'brd_order', 'ASC');
        return $result;
    }


    public function get_one($primary_value = '', $select = '', $where = '')
    {
        $use_cache = false;
        if ($primary_value && empty($select) && empty($where)) {
            $use_cache = true;
        }

        if ($use_cache) {
            $cachename = $this->cache_prefix . $primary_value;
            if ( ! $result = $this->cache->get($cachename)) {
                $result = parent::get_one($primary_value);
                $this->cache->save($cachename, $result, $this->cache_time);
            }
        } else {
            $result = parent::get_one($primary_value, $select, $where);
        }
        return $result;
    }


    public function delete($primary_value = '', $where = '')
    {
        if (empty($primary_value)) {
            return false;
        }
        $result = parent::delete($primary_value);
        $this->cache->delete($this->cache_prefix . $primary_value);
        return $result;
    }


    public function update($primary_value = '', $updatedata = '', $where = '')
    {
        if (empty($primary_value)) {
            return false;
        }

        $result = parent::update($primary_value, $updatedata);
        if ($result) {
            $this->cache->delete($this->cache_prefix . $primary_value);
        }
        return $result;
    }


    public function get_num_row($user_id='')
    {
        
    $this->db->select('mem_id');
    $this->db->where('mem_id',$user_id);
    $query = $this->db->get('board');
    $num = $query->num_rows();
    return $num;

    }


    public function get_group_select($bgr_id = 0)
    {
        $bgr_id = (int) $bgr_id;

        $option = '<option value="0">그룹선택</option>';
        $this->db->order_by('bgr_order', 'ASC');
        $this->db->select('bgr_id, bgr_name');
        $qry = $this->db->get('board_group');
        foreach ($qry->result_array() as $row) {
            $option .= '<option value="' . $row['bgr_id'] . '"';
            if ((int) $row['bgr_id'] === $bgr_id) {
                $option .= ' selected="selected" ';
            }
            $option .= '>' . $row['bgr_name'] . '</option>';
        }
        return $option;
    }

    
}

배강민 / 2016/09/05 10:08:34 / 추천 0

CIBOARD를 커스트마이징 중이신거군요.

해당 cms를 다운받아 대략 보니, 방식은 맞는듯한데, 

기존에 있는 컨트롤러에 수정하는게 아니라, 새로 컨트롤러를 만드신건가요? 그렇다면, 해당 컨트롤러까지 보여주셔야 할 듯 합니다.

만약, 기존에 Borad_model 이란 모델을 사용하고 있는 컨트롤러를 수정하셨는데, 안되시는거라면, CIBOARD 개발사에 직접 문의해보셔야 할 수도 있습니다.

제가 Board_model를 사용하는 컨트롤러를 열어본것은, Boardcounter.php 라는 파일인데, 이 파일에서라면 문제없이 사용이 되야하는 것처럼 보입니다.

추가하신 펑션들 내부 로직 자체가 정상적인데, 말씀하신듯이 펑션을 찾지 못하는 것이라면요.

trace / 2016/09/06 00:14:19 / 추천 0
@배강민 답변감사합니다. 기존 콘트롤러에 수정하는거라 ㅠㅠ 제가 좀더 보겠습니다 관심 가져주셔서 감사합니다