Php codeigniter中的类CI_分页工作不正常?
我尝试使用codeigniter的类分页,但我遇到了一个问题,链接的活动页面总是第一页。 我的控制器代码Php codeigniter中的类CI_分页工作不正常?,php,codeigniter,twitter-bootstrap,Php,Codeigniter,Twitter Bootstrap,我尝试使用codeigniter的类分页,但我遇到了一个问题,链接的活动页面总是第一页。 我的控制器代码 <?php class Users extends CI_Controller { function __construct() { parent::__construct(); $this->is_logged_in(); } function index() { $data['main_
<?php
class Users extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->is_logged_in();
}
function index()
{
$data['main_content'] = 'admin/users_manage';
$data['left_menu'] = 'admin/left_menu_users';
$this->load->view('admin/include/templates_login', $data);
}
function select()
{
$this->load->library('pagination');
$this->load->library('table');
$this->load->model('user_model');
//$this->table->set_heading('Id', 'The Title', 'The Content');
$config['base_url'] = 'http://localhost/cib/index.php/admin/users/select';
$config['total_rows'] = $this->db->get('users_view')->num_rows();
$config['per_page'] = 10;
$config['num_links'] = 20;
//$config['full_tag_open'] = '<div class="pagination">';
//$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config);
$data['records'] = $this->user_model->getUsers($config['per_page'], $this->uri->segment(4));
$data['main_content'] = 'admin/users_manage';
$this->load->view('admin/include/templates_login', $data);
//$this->load->view('admin/site_view', $data);
}
function is_logged_in()
{
$is_logged_in = $this->session->userdata('is_logged_in');
if(!isset($is_logged_in) || $is_logged_in != true)
{
echo 'You don\'t have permission to access this page.';
echo anchor('admin/login/index', 'Login');
die();
//$this->load->view('login_form');
}
}
}
?>
和我的型号代码:
<?php
class User_model extends CI_Model
{
function validate()
{
$username = $this->input->post('username');
$password = $this->input->post('password');
$this->db->where('username', $username);
$this->db->where('password', md5($password));
$query = $this->db->get('users');
if($query->num_rows == 1)
{
return true;
}
return false;
}
function getUsers($num="", $offset="")
{
$this->db->limit($num,$offset);
$query = $this->db->get('users_view');
return $query;
}
}
admin/users_manage.php:
使用CodeIgniter进行超级分页
Controller中的select()函数是使用类CI_分页的函数。我可以获得数据库的不同页面。但是它提供的链接有一个问题,即
第一页链接始终处于活动状态
如您所见,它显示的数据实际上是第11页,但活动链接仍然是第一页。(请注意,我使用了bootstrap和codeigniter)。您需要将此添加到活动页面链接的代码中:
$config['uri_segment'] = $this->uri->segment(4);
您需要将以下内容添加到活动页面链接的代码中:
$config['uri_segment'] = $this->uri->segment(4);
您没有定义
$config['uri_segment']
它现在运行良好,非常感谢。没问题,很高兴help@tomexsans,我有一个关于如何使用类CI_分页的新问题,那就是我想在表的一列中创建modify/delete链接,但是createlinks()函数只能显示我们从数据库中可以看到的内容。因此问题是我如何在表中为修改/删除相应行添加一列您没有定义的$config['uri_segment']
现在运行良好,非常感谢。没问题,很高兴help@tomexsans,我有一个关于如何使用类CI_分页的新问题,也就是说,我想在表的一列中创建modify/delete链接,但是createlinks()函数只能显示我们可以从数据库中获得的内容。因此,问题是如何在表中添加一列,以便修改/删除相应的行
$config['uri_segment'] = $this->uri->segment(4);