我想在我的页面上添加分页,它适用于链接2,3,4等等。但每次我点击第一个和1页面显示我禁止访问,第一个和1给我的链接是“palmydentist / admin / dentist / index /”。我认为问题是/ index /但我不知道如何解决它。如果我点击其他链接例如2“palmydentist / admin / dentist / index / 2 /”它没有给我任何错误。
这是我在控制器中的代码
class dentist_list extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->library('session');
$this->load->database();
$this->load->model('Admin_model', 'Admin');
$this->load->library("pagination");
}
public function index($uri_segment="4")
{
if($this->session->userdata('admin_id'))
{
$data = array();
$config = array();
$config['base_url'] = base_url() . "admin/dentist_list/index/";
$config['total_rows'] = $this->Admin->record_count();
$config['per_page'] = 10;
$config['uri_segment'] = 4;
$config['use_page_numbers'] = TRUE;
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(4) : 0;
$data["patient"] = $this->Admin->dentist_list($config["per_page"], $page);
$data["links"] = $this->pagination->create_links();
$data['table_data'] = $data['patient']['td'];
$data['footer'] = $this->load->view('dentist_dashboard/footer','', true);
$this->load->view('admin/dentist_list', $data);
}
else
{
header('Location: ' . base_url() . 'admin');
}
}
}
不介意模特......
答案 0 :(得分:0)
改变这个:
$config['base_url'] = base_url() . "admin/dentist_list/index/";
要,
$config['base_url'] = base_url() . "dentist_list/index/";
$config['uri_segment'] = 3;
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
答案 1 :(得分:0)
您向$uri_segment="4"
函数提供了一个参数index
,该函数假设您的网址结构始终具有$uri_segment
(在1的情况下不是这样),而且您不是在你的代码中使用该参数。你可以去:
public function index()
答案 2 :(得分:0)
这句话看起来很罕见..
$page = ($this->uri->segment(3)) ? $this->uri->segment(4) : 0;
那么为什么不检查第4段呢?
$page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 1; // I don't know how you paginate the query in you model but the first page is 1
顺便说一句,$ uri_segment参数似乎已经过时了。
PD:我是阿根廷人,我的英语技能有点差......