2012-06-05 4 views
2

내 홈페이지에 블로그 기사 페이지 매기기를 사용하는 것을 시도하고있다 :CodeIgniter의 페이지 매김 - 404 오류

컨트롤러 :

public function index() 
{ 
    $data['view'] = "home"; 

    /** Pagination **/ 
    $config['base_url'] = base_url().'home/'; 
    $config['total_rows'] = $this->Blog_model->count_articles(); 
    $config['per_page'] = 2; 
    $config['uri_segment'] = 2; 

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

    $data['paginate'] = $this->pagination->create_links(); 
    $data['articles'] = $this->Blog_model->get_articles($config['per_page'],$this->uri->segment(2)); 

    $this->load->view('template', $data); 

} 

모든 때, 그러나 정보 검색 및 페이지 매김과 확인 작업 보인다 I 번호 링크 또는 다음 링크를 클릭하십시오. 404 찾을 수 없음 오류가 발생합니다.

URI 세그먼트와 관련이 있다고 가정합니다.

로드되는 URL은 두 번째 페이지의 경우 http://www.example.com/home/2입니다.

답변

2

codeigniter 페이지의 형식은 http://domain.com/controller/method/arguments입니다.
메서드를 생략하면 기본 메서드가로드되지만 인수를 전달해야하는 경우 이전에 메서드를 넣어야합니다.

http://www.example.com/home/index/2 
+0

완벽한 인덱스를 제거하는 전혀 어쨌든, 감사합니다? 나는 SEO의 관점에서 생각하고 있습니까? – ChrisBratherton

+0

[mod_rewrite] (http://httpd.apache.org/docs/current/mod/mod_rewrite.html)로 URL 재 작성을 시도해 볼 수 있습니다. – Musa

4

또한 같은 라우팅 규칙에 추가 할 수 있습니다,의 num이 후 집/인덱스 번호와 경로에있는 URL을 그것을 알려줍니다 색인이나 방법없이 사용할 수있는 다음

$route['home/(:num)'] = 'yourhomecontroller'; 

을 가정의

0

컨트롤러 코드

public function index() 
{ 

$home=$this->uri->segment(2); 

$limit_ti=2; 
if(!$home): 
offset_ti = 0; 
else: 
$offset_ti = $home; 
endif; 


$this->load->model('Blog_model');// call model 
$this->load->library('pagination'); // call library 

$query=$this->Blog_model->get_articles($limit_ti,$offset_ti); // geting aan article 

$total_page = $this->Blog_model->count_articles(); // count row 

/** Pagination **/ 
$config['base_url'] = base_url().'index.php/home/'; // assuming you doesn't have htaccess 
$config['total_rows'] =$total_page->num_rows(); 
$config['per_page'] = 2; 
$config['uri_segment'] = 2; 

    $this->pagination->initialize($config); 
    $data = array('query' => $query,'page'=>$home); 

    $data['view'] = "home"; 
    $this->load->view('template', $data); 

} 

모델 코드

보기
function get_articles($limit,$ofset){ 
$query=$this->db->query("select * from *table* order by id ASC LIMIT $ofset,$limit"); 
return $query; 
} 

function count_articles(){ 
$query=$this->db->query("select * from table"); 
return $query; 
} 

<?php echo $this->pagination->create_links(); // call the pagnation?>