|
本帖最后由 renbaolin 于 2012-10-24 17:24 编辑
修改了ci框架里面自带的分页pagination类,先上图让大家看效果框架版本是CodeIgniter_2.1.3
上代码
控制器代码:
public function index($page=0)
{
$this->load->library('pagination');
$config['base_url']='/index.php/index/page';
$config['total_rows']=$this->home_model->count_column();
$config['per_page']=1;//每页显示多少调数据
$pageNum=$this->uri->segment(3)?$this->uri->segment(3):1;
if($pageNum==1){
$offset=0;
}else{
$offset=$config['per_page']*($pageNum-1);
}
$data['column']=$this->home_model->get_column($config['per_page'],$offset);
$this->pagination->initialize($config);
$data['title']=ucfirst('home');
$this->load->view('common/header',$data);
$this->load->view('home/index',$data);
$this->load->view('common/footer');
}
Model
public function get_column($num,$offset){
$query=$this->db->get('column',$num,$offset);
return $query->result_array();
}
模版View
<div class="main">
<?php foreach($column as $item):?>
<a href="/index.php/view/<?php echo $item['id'];?>"><?php echo $item['name'];?></a>
<a href="/index.php/delete/columnId/<?php echo $item['id'];?>">删除</a> <a href="/index.php/edit/columnId/<?php echo $item['id'];?>">编辑</a><br />
<?php endforeach; echo $this->pagination->create_links();?>
</div>
CSS样式代码
.page {border-top:1px solid #dfdfdf; padding-top: 10px; text-align: left; margin-bottom: 10px; font-size: 14px;}
.page a {margin: 0 5px 0 0; padding: 3px 6px; border: 1px solid #D1D1D1;}
.page .current{margin: 0 5px 0 0; padding: 3px 6px; border: 1px solid #A4A4A4; background:#EBEBEB; }
.page a { color:#333; text-decoration:none;}
.page a:hover {border-color:#AAA !important; background:#FAFAFA; color: #000 !important; text-decoration:underline;}
框架分页pagination类
Pagination.zip
(2.76 KB, 下载次数: 529)
直接替换就行
|
|