<?php
class Paging_demo extends CI_Controller {
	public function index() {
	}
	//http://127.0.0.1:8000/CodeIgniter-3.0.0/paging_demo/paging
	public function paging() {
		// 装载类文件
		$this->load->library ( 'pagination' );
		// 每页显示10条数据
		$page_size = 10;
		
		$this->load->helper('url');
		//配置页面
		$config ['base_url'] = site_url('paging_demo/paging');
		//一共有多少条数据
		$config ['total_rows'] = '200';
		//每页显示条数
		$config ['per_page'] = $page_size;
		
		//分页的数据查询偏移量在哪一段上
		$config['uri_seqment'] = 3;
		
		$config['first_link'] = '首页';
		$config['next_link'] = '下一页';
		$config['last_link'] = '最后一页';
		
		$this->pagination->initialize ( $config );
		
		//http://127.0.0.1:8000/CodeIgniter-3.0.0/paging_demo/paging/190
		//获取链接地址第三段的参数190 与配置$config['uri_seqment']相对应
		$offset = intval($this->uri->segment(3));//intval函数获取数字,无则返回0
		
		$sql = "select * from blog_user limit $offset , $page_size";
		echo $sql.'<br>';
		
		$data['links']=$this->pagination->create_links ();
		
		$this->load->view('user/paging_view',$data);
	}
}