2016-12-05 2 views
1

codeigniter 페이지 매김을 사용하고 있습니다. 하지만 codeingiter 페이지 매김을 사용하는 동안 문제가 발생했습니다. 여기 내가 직면하고있는 문제가 있습니다.Codeigniter 페이지 매김이 작동하지 않습니다.

예 : 한 페이지에 대해 10 개 이상의 레코드가 있고 여기에 페이지 당 5 개의 레코드가 표시됩니다. 두 번째 페이지를 클릭하면 데이터가 올바르게 표시되지만 처음 페이지로 돌아 가야하는 경우 작동하지 않습니다. 여기 내 코드는 다음과 같습니다

컨트롤러 :

class Testimonial extends CI_Controller { 
function __construct() { 
     parent::__construct(); 
     //here we will autoload the pagination library 
     $this->load->model('testimonial_model'); 
     $this->load->library('pagination'); 
    } 
public function index() 
{ 

    $config = array(); 
    $config["base_url"] = base_url('testimonial/index'); 
    $config['total_rows'] = $this->testimonial_model->record_count();//here we will count all the data from the table 
    $config['per_page'] = 2;//number of data to be shown on single page 
    $config["uri_segment"] = 2; 
    $this->pagination->initialize($config); 
    $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0; 
    $data["records2"] = $this->testimonial_model->get_all_testimonials($config["per_page"], $page); 
    $data["links"] = $this->pagination->create_links();//create the link for pagination 
    $data['mainpage'] = "testimonial"; 
    $this->load->view('templates/template',$data); 
} 
} 

모델 :

class Testimonial_model extends CI_Model 
{  
function get_all_testimonials($limit, $start) 
{ 
    $this->db->limit($limit, $start); 
    $this->db->select('T.*'); 
    $this->db->from('testimonials AS T'); 
    $this->db->where(array('T.status'=>1)); 
    $q = $this->db->get(); 
    if($q->num_rows()>0) 
    { 
     return $q->result(); 
    } 
    else 
    { 
     return false; 
    } 
} 

function record_count() 
{ 
    return $this->db->count_all("testimonials"); 
} 
} 
+0

이 URL로 이동하십시오 이해하기 위해 한 번 코드를 읽어 보시기 바랍니다 : http://www.technicalkeeda.com/php-codeigniter/pagination-using-php-codeigniter –

+0

@HardikPaghdar는 이것을 시도하지 못했습니다. 페이지 매기기 만 가져 오는 데이터 가져 오기 – user7047368

+0

완전히 이해하려면 정보가 누락되었습니다. 그러나 ... : 페이지 당 몇 개의 항목을 표시해야합니까? ... 컨트롤러 코드에서 페이지 당 $ config [per_page] 항목을 표시하는 것처럼 보입니다. 코드에서 항상 2! 다음과 같이해야합니다 : $ config [ 'per_page'] = ($ this-> uri-> segment (N))? $ this-> uri-> segment (N) : 2; // 여기서 N은 표시 할 페이지 당 항목을 나타내는 URI 세그먼트입니다. – MarcM

답변

0

사용이 답변이

public function index() 
{ 

    $config = array(); 

    //$config["base_url"] = base_url('testimonial/index'); 

     $get_vars = $this->input->get(); 
     if(is_array($get_vars)) 
     $config['suffix'] = '?'.http_build_query($get_vars,'', "&"); 
     //$config['prefix'] = '?'.http_build_query($get_vars,'', "&"); 
     $config['base_url'] = base_url().$this->router->class.'/index'; 
     $config['first_url'] = $config['base_url'] . (isset($config['suffix'])?$config['suffix']:''); 

    $config['total_rows'] = $this->testimonial_model->record_count();//here we will count all the data from the table 
    $config['per_page'] = 2;//number of data to be shown on single page 


    //this line should be according to url to fetch actual value 
    $config["uri_segment"] = ($this->uri->segment('2')?$this->uri->segment('2'):0); // 2 or 3 based on ur url 


    $this->pagination->initialize($config); 
    $page = $config["uri_segment"]; 
    $data["records2"] = $this->testimonial_model->get_all_testimonials($config["per_page"], $page); 
    $data["links"] = $this->pagination->create_links();//create the link for pagination 
    $data['mainpage'] = "testimonial"; 
    $this->load->view('templates/template',$data); 
} 
+0

페이지는 무엇입니까? 날 설명 할 수있어? 그것은 $ page = $ config [ "uri_segment"];이어야합니다. –

+0

페이지를 찾을 수 없음 – user7047368

+0

페이지의 URL을 찾을 수 없습니까? 그것을 공유하십시오. –

관련 문제