在CodeIgniter中实现分页功能是非常简单的,可以按照以下步骤进行操作:
首先,在application/config目录下的autoload.php文件中加载database库和pagination库:$autoload['libraries'] = array('database','pagination');在Controller中加载pagination库,并设置分页配置参数:$this->load->library('pagination');$config['base_url'] = 'http://example.com/index.php/controller_name/method_name';$config['total_rows'] = $this->your_model->get_total_rows(); // 获取数据总数$config['per_page'] = 10; // 每页显示的数据条数$this->pagination->initialize($config);在Model中编写获取数据的方法:public function get_data($limit, $offset) { $query = $this->db->get('your_table', $limit, $offset); return $query->result();}在Controller中调用Model的方法获取数据,并将数据传递给View:$data['results'] = $this->your_model->get_data($config['per_page'], $this->uri->segment(3));$this->load->view('your_view', $data);在View中显示分页链接:echo $this->pagination->create_links();通过以上步骤,就可以在CodeIgniter中实现简单的分页功能了。可以根据实际需求对分页样式和配置参数进行调整。