我的控制器: -笨分頁器無法正常工作
public function index($id,$page=0) {
$config = array();
$config["base_url"] = base_url() . "index.php/categorypage/index/".$id."/";
$total_row = $this->Categorymodel->record_count($id);
$config["total_rows"] = $total_row;
$config["per_page"] = 20;
$config['use_page_numbers'] = TRUE;
$config['num_links'] = $total_row;
$config['cur_tag_open'] = ' <a class="current">';
$config['cur_tag_close'] = '</a>';
$config['next_link'] = 'Next';
$config['prev_link'] = 'Previous';
$this->pagination->initialize($config);
$page = $this->uri->segment(3) ;
$data["results"] = $this->Categorymodel->fetch_data($config["per_page"], $page,$id);
$str_links = $this->pagination->create_links();
$data["links"] = explode(' ',$str_links);
$this->load->view('frontend/template/other_head');
$this->load->view('frontend/template/category_nav');
$this->load->view('frontend/category_content',$data);
$this->load->view('frontend/template/footer');
}
我的模型
class Categorymodel extends CI_Model {
// Count all record of table "contact_info" in database.
public function record_count($catid) {
//$this->db->where('cat_id',$catid);
$query = $this->db->get("tbl_product");
return $query->num_rows();
}
// Fetch data according to per_page limit.
public function fetch_data($limit,$page, $pageid) {
$this->db->limit(12,$limit);
$this->db->where('cat_id', $pageid);
$query = $this->db->get("tbl_product");
//echo $this->db->last_query();exit;
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;
}
}
我不能得到的 「補償」 值,分頁鏈接不獲取其他價值。請幫我解決這個問題。
首先你不需要包含索引函數'base_url()。 「index.php/categorypage/index /".$ id。」/「;'改爲'base_url()。 「index.php/categorypage /".$ id。」/「;'第二,你可能需要設置你的基本網址並設置一些路線http://www.codeigniter.com/user_guide/general/routing.html#examples – user4419336
你也可以保存一些行,不要把$ row放到新數組中:'return $ query-> result_array();' – cssBlaster21895