【问题标题】:How can I add a page?如何添加页面?
【发布时间】:2014-05-01 13:31:56
【问题描述】:

使用 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;
}

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

【问题讨论】:

  • 每个页面上显示的 2 个结果是相同的,还是有任何变化?
  • 使用 print_r($query->num_rows()) 检查它实际上在做什么。
  • 它显示相同的结果,没有任何变化。 idk 如果我还必须在路线中添加任何内容。我在本地主机上工作,然后将其放在网络上供其他人查看
  • 如果我将 credits/credits 作为 base_url 并为它创建一个函数,它就可以工作。我想要它像 credits/1 而不是 credits/credits/1

标签: php codeigniter pagination


【解决方案1】:

试试这个

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-16
    • 1970-01-01
    相关资源
    最近更新 更多