CI 묻고 답하기

제목 초보자인데 이틀째 업데이트 기능을 해결 못하고 있습니다 도와주세요~
카테고리 CI 2, 3
글쓴이 망둥어찜 작성시각 2017/04/27 09:56:06
댓글 : 9 추천 : 0 스크랩 : 0 조회수 : 20425   RSS

안녕하세요

공부 삼아 생활코딩과, 책, 구글링으로  게시판을 만들고 있는데요 update문제로 속상하네요

function의 인수가 자꾸 부족하다고 뜨는데 어떻게 해야할지 잘 모르겠습니다 ㅠㅠ  

도움 부탁드리겠습니다  

<table 정보>

TABLE topic

id int(11) NOT NULL AUTO_INCREMENT,

title varchar(255) NOT NULL ,

description text NULL ,

created datetime NOT NULL ,

PRIMARY KEY (id)

<model>

function update($id, $data){
    $this->db->set('created', 'NOW()', false);
    $where=  $this->db->where('id', $id);
    return   $this->db->update('topic', $data);
}

<controller>

function update($id)

{
    if (!$this->session->userdata('is_login')) {
        $this->load->helper('url');
        redirect('/auth/login?returnURL=' . rawurldecode(site_url('/country/update')));
    }
    $this->load->view('pheader');
    $this->load->view('paside');
    $this->load->library('form_validation');
    $this->form_validation->set_rules('title', '제목', 'required');
    $this->form_validation->set_rules('description', '본문', 'required');
    if ($this->form_validation->run() == FALSE) {
        $this->load->view('update');
    } else {

        $data = array(
            'title' => $this->input->post('title'),
            'description' => $this->input->post('description')
        );
        $this->countries->update($id, $data);
        $this->load->model('user_model');
        $users = $this->user_model->gets();
        $this->load->helper('url');
        redirect('/country/example2/');
        $this->load->view('pfooter');
    }
}

<error>

An uncaught Exception was encountered

Type: ArgumentCountError

Message: Too few arguments to function Country::update(), 0 passed in C:\Apache24\htdocs\system\core\CodeIgniter.php on line 532 and exactly 1 expected

Filename: C:\Apache24\htdocs\application\controllers\country.php

Line Number: 122

Backtrace:

File: C:\Apache24\htdocs\index.phpLine: 315Function: require_once

 다음글 hook 제대로 작동 되지 않는 현상 (3)
 이전글 get_where()은 자동으로 이스케이프해주나요?+세... (2)

댓글

kaido / 2017/04/27 10:02:56 / 추천 0
에러메세지도 같이 올려주세요.
망둥어찜 / 2017/04/27 10:08:44 / 추천 0
에러 메세지도 올렸습니다
kaido / 2017/04/27 10:15:24 / 추천 0
$this->countries  

해당 하는 객체가 없는것으로 보입니다.

모델 호출 부분을 체크해 보세요.

 

http://www.ciboard.co.kr/user_guide/kr/libraries/loader.html

모델 관련 로드 부분 확인해 보세요.

 

 

//만일 countries 해당 모델을 사용 하신다면

$this->load->model('countries_model', 'countries');
$this->countries->update($id, $data);

 

이런 형식이 되셔야 할것입니다.

망둥어찜 / 2017/04/27 10:21:19 / 추천 0
답변 감사합니다 노력 해보겠습니다
변종원(웅파) / 2017/04/27 10:31:56 / 추천 0
모델 로딩을 안했을 수도 있습니다.
망둥어찜 / 2017/04/27 10:37:00 / 추천 0
모델은 생성자쪽에서 로드 하고 있는데 잘못된 방법 일까요?
한대승(불의회상) / 2017/04/27 10:51:29 / 추천 0
@망둥어찜 컨트롤러 전역적으로 사용된다면 좋은 방법입니다.
한대승(불의회상) / 2017/04/27 10:54:50 / 추천 1

컨트롤러 호출 하실때 country/1 <= 이러식으로 아이디를 지정해서 호출하고 있나요?

에러메시지상으론 인자 값이 넘어 오지 않아 에러가 발생한거네요.

망둥어찜 / 2017/04/28 15:15:15 / 추천 0
답변 감사합니다 선배님들의 댓글덕에 해결 할 수 있었습니다