我该如何添加页面?

时间:2014-04-10 08:38:58

标签: php codeigniter pagination

使用CodeIgniter 2.0.2

我想为我的网站设置分页。

这就是我在控制器中的内容:

$config = array();
$config["base_url"] = base_url() . "/credits";
$config['total_rows'] = 200;
$config['per_page'] = 2; 
$config["uri_segment"] = 3;

$this->pagination->initialize($config);

$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data["results"] = $this->credits_model->fetch_countries($config["per_page"], $page);
$data["links"] = $this->pagination->create_links();

型号:

public function record_count() {
    return $this->db->count_all("sadmin_credits");
}

public function fetch_countries($limit, $start) {
    $this->db->limit($limit, $start);
    $query = $this->db->get("sadmin_credits");

    if ($query->num_rows() > 0) {
        foreach ($query->result() as $row) {
            $data[] = $row;
        }
        return $data;
    }
    return false;
}

我需要一些帮助才能让它发挥作用。它显示了数字,但是当我点击它们时,它只显示相同的结果,没有任何变化。

1 个答案:

答案 0 :(得分:0)

试试这个

public function credits($offset='')
{
    $total_rows = $this->credits_model->record_count();
    $config['base_url'] = base_url() . "/credits";
    $config['total_rows'] = $total_rows;
    $config['per_page'] = 2; 

    $this->pagination->cur_page = $offset;
    $this->pagination->initialize($config);  
    $data["results"] = $this->credits_model->fetch_countries($config["per_page"], $offset);
    $data["links"] = $this->pagination->create_links();
}

或查看本教程

http://only4ututorials.blogspot.in/2014/04/pagination-with-codeigniter.html