2014-01-23 100 views
-1

控制器:CI分页无法正常工作?

function __construct() 
    { 
     parent::__construct(); 
     $this->load->library('form_validation'); 
     $this->load->library('session'); 
     $this->load->helper('form'); 
     $this->load->helper('url'); 
     $this->load->library('cart'); 
     $this->load->database(); 
     $this->load->model('user_model'); 
     $this->load->library("pagination"); 

//$this->load->library('result/Apache/Solr/apache_solr_service');  

     $this->load->library('email'); 
    } 


public function index() 
    { 

     $config["base_url"] = base_url() . "index.php/index/index"; 
     //print_r($config["base_url"]); 
     $config["total_rows"] = $this->user_model->record_count(); 
     $limit = $config["per_page"] = 9; 
     $config["uri_segment"] = 2; 
     //$config['use_page_numbers'] = TRUE; 
     $data['count']= $this->user_model->record_count(); 
     //print_r($data['count']); 
     $this->pagination->initialize($config); 
     $start = ($this->uri->segment(2))? $this->uri->segment(2) : 0; 
     $data["data"] = $this->user_model->product($limit,$start); 
     $data["links"] = $this->pagination->create_links(); 
     print_r($data['links']); 

print_r($data['data']); 

     //$this->load->view("pagination", $data); 

     //$this->load->view('inc/header'); 

     //$data['data']=$this->user_model->product(); 

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

     //$this->load->view('inc/footer'); 
    } 

型号:

public function product($limit, $start) 
    {  
     $this->db->select('*'); 
     $this->db->order_by("id", "asc"); 

     $this->db->limit($limit, $start); 

     $query=$this->db->get('newdeal'); 

     return $query->result_array(); 

} 
+1

$ config [“uri_segment”] = 3; –

+0

正如旁注所示,您可以将它们的所有加载程序加载到自动加载中,以便它们不需要包含在每个控制器的顶部。 – Albzi

+0

Nouphal.M我试着这个$ config [“uri_segment”] = 3;但价值保留不变 – user3060459

回答

0

如Nouphal.M在意见提出,更改

$config['uri_segment'] = 2; 

$config['uri_segment'] = 3; 

另外,作为侧不e,你可以通过把你的助手/库自动加载到

application > config > autoload.php 

然后把库/助手放在正确的数组中。例如

$data['helper'] = array("url", "email", "form");