CI 묻고 답하기

제목 페이징 및 검색 부분....에러 ㅜㅡ
글쓴이 띠벙이 작성시각 2015/02/02 22:14:49
댓글 : 2 추천 : 0 스크랩 : 0 조회수 : 17435   RSS
검색시 : http://test.cafe24.com/code/index.php/topic/index/q/j/page/1
 $uri_segment = 5; 가 된다.. 맞나요.?

페이징시 : http://test.cafe24.com/code/index.php/topic/index/page/3
 $uri_segment = 3; 가 된다.. 맞나요.? 

쿼리를 찍어보면.. limit 이 -3..이 되요.ㅜㅡ
SELECT * FROM table WHERE 1=1 ORDER BY reg_date DESC LIMIT -3, 3


* 컨트롤러 부분

    function index(){        
    
        
        $this->_head();
        
        $this->output->enable_profiler(TRUE);
        $search_word = $page_url = ''; 
        $uri_segment = 3; 
        
        //주소중에서 q(검색어) 세그먼트가 있는지 검사하기 위해 주소를 배열로 변환 
        $uri_array = $this->segment_explode($this->uri->uri_string()); 
        if( in_array('q', $uri_array) ) { 
            //주소에 검색어가 있을 경우의 처리. 즉 검색시 
            $search_word = urldecode($this->url_explode($uri_array, 'q')); 
            //페이지네이션용 주소 
            $page_url = '/q/'.$search_word; 
            $uri_segment = 5; 
        } 
        //페이지네이션 라이브러리 로딩 추가 
        $this->load->library('pagination'); 

        
        $config=array();

        $config['base_url'] = '/code/index.php/topic/index'.$page_url.'/page/'; //페이징 주소
        $config['total_rows'] = $this->topic_model->get_list('table', 'count', '', '', $search_word); //게시물의 전체 갯수 

        $config['per_page'] = 3; 
        $config['uri_segment'] = $uri_segment; //페이지 번호가 위치한 세그먼트 
        
        
        //$config넘겨준다.
        $this->pagination->initialize($config); 
        $data['pagination'] = $this->pagination->create_links();
         
        //게시판 목록을 불러오기 위한 offset, limit 값 가져오기 
        $data['page'] = $page = $this->uri->segment($uri_segment, 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->topic_model->get_list('table', '', $start, $limit, $search_word); 
        $this->load->view('main2',$data);
        
         
        $this->load->view('footer');
        

    }
 다음글 library, model 로드 선언 위치 질문입니다. (5)
 이전글 사용자 라이브러리를 호출하면 백지가 출력됩니다.. (3)

댓글

한대승(불의회상) / 2015/02/03 09:35:59 / 추천 0
1씩 더해보세요.
변종원(웅파) / 2015/02/03 12:10:22 / 추천 0
http://cikorea.net/user_guide_2.1.0/libraries/uri.html  

매뉴얼 다시 보시고 index.php가 0입니다. 그 뒤로 숫자를 세어보세요