【发布时间】:2015-08-05 02:59:58
【问题描述】:
我正在做我朋友的一个项目,这是使用 codeigniter 构建的,它使用模板运行。所以我的问题是,当我使用分页时,它可以正确查看,但是当我单击第二页按钮时,它会在主页上加载相同的数据。
这是我的代码..
用于加载主模板的控制器。
public function pg(){
$this->template->attach($this->resours);
$this->template->draw('student/view_pg',true);
$this->load->view('student/view_pg');
}
用于加载分页视图的控制器。
function pg_index($offset=0,$order_column='st_id',$order_type='asc')
{
$this->load->helper('url');
//Check for valid column
if(empty($offset)) $offset=0;
if(empty($order_column)) $order_column='st_id';
if(empty($order_type)) $order_type='asc';
//load data
$Students=$this->Student_model->get_paged_list($this->limit,$offset,$order_column,$order_type)->result();
//print_r($Students);
//genarate pagination
$this->load->library('pagination');
//$config['base_url']=site_url('student/pg_index/');
$config['base_url']=site_url('student/pg/');
$config['total_rows']=$this->Student_model->count_all();
$config['per_page']=$this->limit;
$config['uri_segment']=3;
$this->pagination->initialize($config);
$data['pagination']=$this->pagination->create_links();
//genarate table data
$this->load->library('table');
$this->table->set_empty(" ");
$new_order=($order_type=='asc' ? 'desc' : 'asc');
$this->table->set_heading(
'St_id', 'name',
'address',
'number',
'email',
'Actions'
);
$i=0+$offset;
foreach($Students as $Student)
{
$this->table->add_row(++$i,
$Student->name,
$Student->address,
$Student->number,
$Student->email,
anchor('get_detail_st(<?php echo $value->st_id;?>);'.$Student->id,'update',array('class'=>'Delete')),
anchor('Student/delete/'.$Student->id,'delete',array('class'=>'Delete'))
);
}
$data['table'] = $this->table->generate();
$this->load->view('student/Student_pg_crud',$data);
}
分页视图 student_pg_crud
<body>
<div class="content">
<div class="data"><?php echo $table; ?></div>
<div class="paging"><?php echo $pagination; ?></div>
<br />
<?php echo anchor('Student/add/','Add new students',array('class'=>'add')); ?>
</div>
</body>
</html>
绘制主视图。 /view_pg
$_instance = get_instance()
?>
<table width="100%" border="0" cellpadding="10">
<tr class="ContentTableTitleRow" width="100%">
<td style="vertical-align: top" width="100%">View Student</td>
</tr>
<tr>
<td style="vertical-align: top"><?php $_instance->pg_index(); ?></td>
</tr>
</table>
这里有什么问题..我是codeigniter的初学者,有没有比这更能在codeigniter中使用模板的方法?
【问题讨论】:
标签: php codeigniter pagination