我是CodeIgniter框架的新手,我正在尝试使用分页类。所以我遇到了一些麻烦。
场合 数据显示没问题。但是转到表的其他页面的链接却无法正常工作。当我点击“1,2,3”按钮时,它不会用于其他数据。它仍然在同一个地方。
问题 我的代码的主要问题是什么?
我的控制器:
public function view_all_staff() {
if(!$this->user_auth_model->logged_in()) {
redirect('user/login');
} else {
$config = array();
$limit = 1;
$this->load->library('pagination');
$this->load->library('table');
$uri_segment = 4;
$offset = $this->uri->segment($uri_segment);
$config['base_url'] = base_url() . 'admin/view_all_staff';
$admin = "Admin";
$query = $this->db->query("SELECT * FROM admin where login_type = '".$admin."'");
$config['total_rows'] = $query->num_rows();
$config['per_page'] = $limit;
$config['uri_segment'] = $uri_segment;
$config['cur_tag_open'] = '<li class="active"><a href="' . base_url() . $this->uri->uri_string() . '">';
$config['cur_tag_close'] = '</a></li>';
$this->pagination->initialize($config);
$this->pagination->initialize($config);
$sel = $this->db->select('*');
$sel = $this->db->where('login_type =', 'Admin');
$records = $this->db->get('admin', $config['per_page'], $this->uri->segment(4));
foreach ($records->result() as $item) {
$q[] = $item;
}
$data['records'] = $q;
$data['total_rows'] = $query->num_rows();
$data['per_page'] = $limit;
$data['uri_segment'] = $uri_segment;
$data['create_staff_suc'] = $this->session->flashdata('create_staff_suc');
$this->load->view('header');
$this->load->view('browse_staff_view', $data);
}
}
我的观点:
<tr><td colspan="5" style="margin-top: inherit; text-align: right;"> <?php echo $this->pagination->create_links(); ?></td></tr>
<?php } else { ?>
<tr><td colspan="5" style="margin-top: inherit; text-align: center;"> <?php echo "No Records Found"; ?></td></tr>
<?php } ?>
我希望有人能告诉我这是什么问题。
答案 0 :(得分:0)
我认为您的$uri_segement
需要为3而不是4,基于您的base_url仅使用2个细分(admin/view_all_staff
)。