2012-03-02 2 views
2

I 데이터를 획득 paginatiom CodeIgniter로의 관리 제어기CodeIgniter의 페이징 오류 404

class Admin extends CI_Controller { 

function __construct() { 

    parent::__construct(); 

    if (!$this->tank_auth->is_logged_in()) redirect('login'); 
    $this->load->library('pagination'); 

} 

function index() { 

    $offset = $this->uri->segment(2); 
    $config['per_page'] = 3; 
    $data['sitetitle'] = 'Výpis jobů'; 
    $data['listings'] = $this->Jobs_model->get_listings(0,$user_id = FALSE,$config['per_page'],$offset); 
    $config['uri_segment'] = 2; 
    $config['base_url']  = base_url().'admin/'; 
    $config['total_rows'] = $this->db->count_all_results('jobs'); 


    $this->pagination->initialize($config); 

    $this->template->set('title', 'Domovská stránka'); 
    $this->template->load('template', 'site', $data); 
} 

}

및 Jobs_model

function get_listings($category, $user_id = false, $limit = 0, $offset = 0) { 

    $data = array(); 

    $this->db->order_by('id', 'desc'); 
    $q = $this->db->get('jobs'); 

    if ($category) { 
     $options = array('category' => $category); 
     $this->db->order_by('id', 'desc'); 
     $this->db->where('category', $category); 
     $q = $this->db->get('jobs', $limit, $offset); 
    } 
    else { 
     $query = $this->db->order_by('id', 'desc'); 
     if ($user_id) $query = $query->where('user_id', $user_id); 
     $q = $query->get('jobs',$limit, $offset); 
    } 

    if ($q->num_rows() > 0) { 
     foreach ($q->result_array() as $row) { 
      $data[] = $row; 
     } 
    } 

    $q->free_result(); 
    return $data; 
} 

첫 페이지가 있지만 매김 로컬 호스트에서 생성 링크/사이트 이름/admin/3은 404 오류를 생성합니다.

$config['base_url'] = base_url().'admin/'; 

에 : : 문제는 내 스크립트에 이

답변

4

당신은 변경해야 당신이 필요 URL이 admin/3처럼 될 경우

$config['base_url'] = base_url().'admin/index/'; 

, 당신이 사용할 수있는 route 또는 _remap.

사이드 참고 :

function index($offset = 0) { 
    // your code 
} 

그것은 같은 일을 할 것이다, 그러나 가능하면 컨트롤러 메소드 인수를 사용하는 것이 편리 다음 URI 클래스보다는 페이지 번호를 얻기 위해 이것을 사용하는 것이 좋습니다.

1

일부 변경해야합니다.

$config['base_url']=base_url().'admin/index'; 

변화

$config['uri_segment'] = 3; 

체크를하면 htaccess로를 사용하거나하지 않는 경우.)

1 컨트롤러 그것의 인덱스를 확인하거나 : 당신이하지 않은 경우 당신은 follwing을 일을 확인하시기 바랍니다 코드 이그나이터의 paggination에 404 오류가 발생하는 경우, 다음 위의 $ 설정 [ 'BASE_URL는']

$config['base_url']=base_url().'index.php/admin/index'; 
+0

나는 @itachi에 동의합니다. –

0

을해야한다

base_url().'admin/index/pages'하고 일도 사람의 경우는 다음과 같아야합니다 : 다른 뭔가를해야만 그것의 인덱스는 BASE_URL은 할 필요가있는 경우

base_url().'admin/somethingelse/pages'

2) 'uri_segment'를 $this->uri->segment(4)으로 확인하십시오. 이렇게하면 페이지 번호를 얻고 그 다음으로 codiegniter를 수행합니다.