CI 묻고 답하기

제목 글 작성시 여러페이지로 나눌때
카테고리 CI 2, 3
글쓴이 책상다리 작성시각 2020/11/25 12:55:24
댓글 : 3 추천 : 0 스크랩 : 0 조회수 : 7421   RSS

CI 3.xx버전입니다.

부득이하게 글을 등록할때 2~3단계로 나누어서 글을 등록하게 되어있는데, 이를 CI .로 좀 매끄럽게 구성해보고 싶습니다.

안에 들어가는 상세 코드는 대충 복붙이고, test/write/1에서 글쓰기 완료하면 test/write/2로 넘어가서 글쓰고, 뭐 그런식으로 진행되는데,

이 페이지를 나누는 방법이 혹시 좀더 매끄러운 방법이 있을까 해서 질문올려봅니다.

너무 지저분해보입니다..ㅜㅜ

    public function write()
    {
        if(@$this->session->userdata['logged_in'] == TRUE )
        {
            if($this->uri->segment(3) == '1')
            {
                $this->load->library('form_validation');
                if($this->form_validation->run('write_form') == FALSE)
                {
                    $this->load->view('test/write_v');
                }
                else
                {
                    $write_arrays = array(
                        'idx' => $this->input->post('idx',TRUE),
                        'subject' => $this->input->post('subject',TRUE),
                        'content' => $this->input->post('content',TRUE)
                    );

                    $result = $this->write_m->insert($write_arrays);
                    if($result)
                    {
                        redirect('/test/write/2');
                    }
                }
            }
            elseif($this->uri->segment(3) == '2')
            {
                $this->load->library('form_validation');
                if($this->form_validation->run('write_form') == FALSE)
                {
                    $this->load->view('test/write_v');
                }
                else
                {
                    $write_arrays = array(
                        'idx' => $this->input->post('idx',TRUE),
                        'subject' => $this->input->post('subject',TRUE),
                        'content' => $this->input->post('content',TRUE)
                    );

                    $result = $this->write_m->insert($write_arrays);
                    if($result)
                    {
                        redirect('/test/write/3');
                    }
                }
            } 
        }
    }
 다음글 세션 종료 문제 (2)
 이전글 버전 2.x 사용중입니다. chr(30) 인식불가 현상... (4)

댓글

변종원(웅파) / 2020/11/25 13:09:19 / 추천 0
반복되는 부분을 라이브러리화 하시면 될 것 같습니다.
PureAni / 2020/11/25 13:31:23 / 추천 0

if 문 안의 내용이 redirect('/test/write/3'); 를 제외하면 동일한듯합니다.

하나로 통일시키고, redirect('/test/write/3'); 를 redirect('/test/write/' . ($this->uri->segment(3) + 1)); 하시면..

책상다리 / 2020/11/25 13:41:14 / 추천 0

변종원님 // 일단 저렇게 페이지를 나눠도 문제는 없는거군요 감사합니다.

PureAni님// 아..그런 방법도 있었네요; 감사합니다