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");
}
}
이 URL로 이동하십시오 이해하기 위해 한 번 코드를 읽어 보시기 바랍니다 : http://www.technicalkeeda.com/php-codeigniter/pagination-using-php-codeigniter –
@HardikPaghdar는 이것을 시도하지 못했습니다. 페이지 매기기 만 가져 오는 데이터 가져 오기 – user7047368
완전히 이해하려면 정보가 누락되었습니다. 그러나 ... : 페이지 당 몇 개의 항목을 표시해야합니까? ... 컨트롤러 코드에서 페이지 당 $ config [per_page] 항목을 표시하는 것처럼 보입니다. 코드에서 항상 2! 다음과 같이해야합니다 : $ config [ 'per_page'] = ($ this-> uri-> segment (N))? $ this-> uri-> segment (N) : 2; // 여기서 N은 표시 할 페이지 당 항목을 나타내는 URI 세그먼트입니다. – MarcM