ci的分页问题(有代码)
为什么我点击分页的1234都没反应,他直接显示我所有的数据controllers的代码
<?php
class Information extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('information_model');
$this->load->helper('url_helper');
}
public function a()
{
$data['information'] = $this->information_model->get_information();
$config['base_url'] = base_url().'index.php/information/a';
$config['total_rows'] = 8;
$config['per_page'] = 2;
$config['first_link'] = '首页';
$config['last_link'] = '尾页';
$config['full_tag_open'] = '<p>';
$config['full_tag_close'] = '<p>';
$this->table->set_heading('id','bb','cc','dd','ee','ff','gg');
$this->pagination->initialize($config);
$this->load->view('information/a',$data);
}
}
model代码
<?php
class information_model extends CI_Model {
public function __construct()
{
$this->load->database();
}
public function get_information()
{
$query = $this->db->get('information');
return $query->result_array();
}
}
view代码
<!DOCTYPE html>
<html>
<body>
<?php echo $this->table->generate($information);?>
<?php echo $this->pagination->create_links();?>
</body>
</html> 你的 model 需要支持按页取数据呀,分页类只是帮你从行为上分页,而数据是不是分页要你自己控制。
分页类用法本论坛有教程的。 2楼正解。
建议重写 model get_infomation()
/*获取指定的记录
* $page 页码
* $row 每页现实的记录数量
*
*/
public function get_infomation($page=1,$row=8)
{
$query = $this->db->get('infomation',($page-1)*$row,$row);
return $query->result_array();
} 不好意思上面的代码有点错误 应该是:
$query = $this->db->get('infomation',$row,($page-1)*$row);
页:
[1]