我现在尝试在我的网络应用程序中使用分页,但它不起作用。当我单击由 创建的链接时$this->pagination->create_links()
,我收到 404 页面错误。
这是我的控制器:
function index($id) {
$this->load->library('pagination');
if($project = $this->projects_model->get($id)) {
$temp = $this->project_logs_model->get_by('project_id', $project->id);
//$config = array();
//$config['base_url'] = base_url().'projects/'.$project->id.'/';
$config['base_url'] = current_url();
$config['total_rows'] = $temp->num_rows();
$config['uri_segment'] = 3;
$config['per_page'] = 5;
$config['first_link'] = 'Latest';
$config['last_link'] = 'Oldest';
$config["num_links"] = 2;
//$config['use_page_numbers'] = TRUE;
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$this->check_access($project);
$this->data->current_project = $project;
$this->data->updates = $this->project_logs_model->get_by('project_id', $project->id, $config['per_page'], $page);
$this->data->links = $this->pagination->create_links();
$this->view('project-main', $this->data);
} else {
show_404();
}
}
$id
传递给索引用于确定要查看哪个项目,也用于查看该项目的 project_logs,所以我真的无法删除。这意味着如果我使用分页,页码将是第二个参数。