CI 묻고 답하기

제목 게시판 글쓰기 질문
카테고리 CI 2, 3
글쓴이 yumin 작성시각 2018/12/19 17:14:59
댓글 : 1 추천 : 0 스크랩 : 0 조회수 : 15983   RSS

만들면서 배우는 ci로 게시판 만들기를 하면서 공부를 하고있습니다 

질문은 여기서 글쓰기를 진행을 하고 글 리스트 페이지로 이동을 하는게 아니라 내가 쓴글을 확인하는 페이지로 가고 싶은데

해봐도 잘안되네요

글작성이 완료되고면  글쓰기 함수 컨트롤로러에서 아이디값을 모델로  값을 넘겨서 그걸 다시 받아서 uri출력을 생각하고 있는데 

이생각이 잘못이 된건가요 (

/bbs/index.php/board/lists/'.$this->uri->segment(3).'/'.$id 이렇게요

)

제가 알고 있는 범위에서 계속 코드를 작성을 해봤는제 전혀안되네요. 좀 알려주세요 ㅠㅠㅠ 소스 첨부합니다. 이소스는 글작성이되면 글목록으로 넘어가는 소스입니다

 

CONTROll

function write() {
    echo '<meta http-equiv="content-type" content="text/html; charset=utf-8" />';
    $this -> output -> enable_profiler(TRUE);

    if ($_POST) {
        // 글쓰기 POST 전송 시

        $this -> load -> helper('alert');


        if (!$this -> input -> post('subject', TRUE) AND !$this -> input -> post('contents', TRUE)) {
            // 글 내용이 없을 경우, 프로그램 단에서 한 번 더 체크
            alert('비정상적인 접근입니다.', '/bbs/index.php/board/lists/' . $this -> uri -> segment(3) . '/page/');
            exit ;
        }

        // var_dump($_POST);
        $write_data = array(
            'table' => $this -> uri -> segment(3),
            'subject' => $this -> input -> post('subject', TRUE),
            'contents' => $this -> input -> post('contents', TRUE)
        );

        $result=$this -> board_m -> insert_board($write_data);

        if ($result) {
            alert("입력되었습니다.",'/bbs/index.php/board/lists/'.$this->uri->segment(3).'/');
            exit;
        } else {
            alert("다시 입력해주세요.",'/bbs/index.php/board/lists/'.$this->uri->segment(3).'/page/');
            exit;
        }
    } else {
        $this->load->view('board/write_v');
    }
}

----------------------------------------------------------------------------------------------------------------------------

MODEL

function insert_board($arrays) {
    $insert_array = array(
        'board_pid' => 0,
        'user_id' => 'advisor',
        'user_name' => 'palpit',
        'subject' => $arrays['subject'],
        'contents' => $arrays['contents'],
        'reg_date' => date("Y-m-d H:i:s")
    );

    $result=$this->db->insert($arrays['table'], $insert_array);

    return $result;

}
 다음글 호스팅 404 에러 질문 입니다~!! (10)
 이전글 이메일 보내는 사람 설정 관련 질문입니다. (4)

댓글

kaido / 2018/12/19 18:39:36 / 추천 0

  $status = $this->db->insert($arrays['table'], $insert_array);
$insert_id = null;

  if($status){
  //성공이면
  $insert_id = $this->db->insert_id();
  }
$result['status'] = $status;
$result['insert_id'] = $insert_id;

    return $result;

 

 

이런식으로 받아서 처리 하시면 간편합니다.

insert_id 함수가 현재 작성한 글의 id 값을 리턴해줍니다.