分页
首先,配置
$this->load->library('pagination'); $config = array(); // $this->config->load('pagination'); $config["base_url"] = site_url('lift/index'); $config["total_rows"] = $this->Lift_model->record_count(); $config["per_page"] = 15; $config["uri_segment"] = 3; $config['use_page_numbers'] = TRUE; $this->pagination->initialize($config); $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 1; $data["lm_lift"] = $this->Lift_model->get_lifts($config["per_page"], $page); $data["links"] = $this->pagination->create_links(); $this->load->view('lift/index',$data);
前端输出
样式美化,这里以bootstrap pagination为例子,在config目录下添加pagination.php的配置
";$config['full_tag_close'] ="";$config['num_tag_open'] = '
分页保持查询条件
http不能保持状态,可以通过session,uri来保持。如果要用uri来保持状态的话,就需要把查询表单修改为get提交方式。'get')); ?>
需要用的配置项:
$config['suffix'] = ''; 给路径添加一个自定义后缀,后缀位于偏移段的后面。$config["base_url"] = site_url('c/search');if (count($get) > 0) { $config['suffix'] = '?' . http_build_query($get, '', "&"); }$config['first_url'] = site_url('c/search/1?') . http_build_query($get, '', "&query=true"); //修复第一页bug.是Pagination.php自作聪明地将第一页认为总是不必加分页号.
防止静态文件被跳转
RewriteEngine onRewriteCond %{REQUEST_FILENAME} !-f #tells mod_rewrite ignore the url if it's an actual file, and RewriteCond %{REQUEST_FILENAME} !-d #tells it to ignore it if it's a directory.RewriteCond $1 !^(index\.php|contact\.php|images|css|js|video|robots\.txt)RewriteRule ^(.*)$ index.php/$1 [L]