Codeigniter - Next 按钮更改页面上的值和数据,但 "active" class 不会更改
Codeigniter - The Next button changes the value and data on the page, but it the "active" class doesn't change
我想做的是创建一个分页功能。我已经成功地创建了它。有用。 URI 段改变了一切。这是完美的。但是,有一个小问题。当我按 "next" 按钮或按另一个数字转到下一页时,由于某种原因 "page 1" 仍然突出显示。我无法单击它转到第一页。 "Previous" 按钮也会出现。因此,在我转到第二页或除第 1 页以外的任何其他页面后,我无法返回到第一页。我可以返回第一页的唯一方法是更改 URI 段。
我找不到这个具体问题的答案,非常感谢您的帮助。
谢谢。
我的模特:
public function record_count_sitelog()
{
$uid = $this->uri->segment(4);
return $this->db->get_where('site_log', array('uid' => $uid))->num_rows();
}
public function fetch_users_sitelog($limit, $start)
{
$this->db->order_by("time", "desc"); //ordering it in descending order
$uid = $this->uri->segment(4);
$this->db->limit($limit, $start);
$query = $this->db->get_where('site_log', array('uid' => $uid));
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;
}
我的控制器:
public function site_log() {
$uid = $this->uri->segment(4);
$data = array( 'uid' => $uid
);
$this->load->model('Model_Admin_Pagination');
$this->load->library('pagination');
$this->load->library('table');
$config = array();
$config["base_url"] = base_url() . "admin/users/site_log/". $uid ."/";
$this->db->select('*');
$config["total_rows"] = $this->Model_Admin_Pagination->record_count_sitelog();
$config["per_page"] = 20;
$config["uri_segment"] = 4;
$config["num_links"] = 3;
$config['records'] = $this->db->select('*');
//styling it
$config['full_tag_open'] = '<div class="pull-right"> <ul class="pagination">';
$config['full_tag_close'] = '</div></ul>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['next_link'] = '→';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['prev_link'] = '←';
$config['cur_tag_open'] = '<li class="active"><a>';
$config['cur_tag_close'] = '</li></a>';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['last_link'] = '»';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['first_link'] = '«';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
//end styling it
$page = ($this->uri->segment(5)) ? $this->uri->segment(5) : 0;
$data["results"] = $this->Model_Admin_Pagination->
fetch_users_sitelog($config["per_page"], $page);
$data["links"] = $this->pagination->create_links();
$this->pagination->initialize($config);
$this->load->view('admin/includes/header');
$this->load->view('admin/view_site_log', $data);
}
我的看法:
<?php
if (is_array($results))
{
foreach ($results as $data) { ?>
<div> <!--class="col-md-6 col-sm-6"-->
<div class="well pretty-text">
<p>
<h3><font color="#708090">Time:</font> <?php echo date("g:i A", strtotime($data->time)). ' on ' . date("F j, Y", strtotime($data->time)) ?><br></h3>
<b>Current URL:</b> <?php echo $data->current_url ?><br>
Referrer: <?php echo $data->referrer ?><br>
<b>Browser:</b> <?php echo $data->browser ?><br>
Mobile: <?php echo $data->mobile ?><br>
<b>Platform:</b> <?php echo $data->platform ?><br>
<b>User Agent:</b> <?php echo $data->user_agent ?>
</p>
</div>
</div>
<?php } } ?>
<?php echo $this->pagination->create_links(); ?>
你说你的uid
是$this->uri->segment(4);
。如果那是 segment(4)
,那么在你的控制器中,你说 $config["uri_segment"] = 4;
如果您的 URL 类似于:http://example.com/profile/view/1/10
其中 1
是 uid
,那么您应该更改 [=15= 中的 4
] 到 5
.
所以我会替换这一行(在你的控制器中):
$config["uri_segment"] = 4;
与:
$config["uri_segment"] = 5;
我想做的是创建一个分页功能。我已经成功地创建了它。有用。 URI 段改变了一切。这是完美的。但是,有一个小问题。当我按 "next" 按钮或按另一个数字转到下一页时,由于某种原因 "page 1" 仍然突出显示。我无法单击它转到第一页。 "Previous" 按钮也会出现。因此,在我转到第二页或除第 1 页以外的任何其他页面后,我无法返回到第一页。我可以返回第一页的唯一方法是更改 URI 段。
我找不到这个具体问题的答案,非常感谢您的帮助。 谢谢。
我的模特:
public function record_count_sitelog()
{
$uid = $this->uri->segment(4);
return $this->db->get_where('site_log', array('uid' => $uid))->num_rows();
}
public function fetch_users_sitelog($limit, $start)
{
$this->db->order_by("time", "desc"); //ordering it in descending order
$uid = $this->uri->segment(4);
$this->db->limit($limit, $start);
$query = $this->db->get_where('site_log', array('uid' => $uid));
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;
}
我的控制器:
public function site_log() {
$uid = $this->uri->segment(4);
$data = array( 'uid' => $uid
);
$this->load->model('Model_Admin_Pagination');
$this->load->library('pagination');
$this->load->library('table');
$config = array();
$config["base_url"] = base_url() . "admin/users/site_log/". $uid ."/";
$this->db->select('*');
$config["total_rows"] = $this->Model_Admin_Pagination->record_count_sitelog();
$config["per_page"] = 20;
$config["uri_segment"] = 4;
$config["num_links"] = 3;
$config['records'] = $this->db->select('*');
//styling it
$config['full_tag_open'] = '<div class="pull-right"> <ul class="pagination">';
$config['full_tag_close'] = '</div></ul>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['next_link'] = '→';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['prev_link'] = '←';
$config['cur_tag_open'] = '<li class="active"><a>';
$config['cur_tag_close'] = '</li></a>';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['last_link'] = '»';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['first_link'] = '«';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
//end styling it
$page = ($this->uri->segment(5)) ? $this->uri->segment(5) : 0;
$data["results"] = $this->Model_Admin_Pagination->
fetch_users_sitelog($config["per_page"], $page);
$data["links"] = $this->pagination->create_links();
$this->pagination->initialize($config);
$this->load->view('admin/includes/header');
$this->load->view('admin/view_site_log', $data);
}
我的看法:
<?php
if (is_array($results))
{
foreach ($results as $data) { ?>
<div> <!--class="col-md-6 col-sm-6"-->
<div class="well pretty-text">
<p>
<h3><font color="#708090">Time:</font> <?php echo date("g:i A", strtotime($data->time)). ' on ' . date("F j, Y", strtotime($data->time)) ?><br></h3>
<b>Current URL:</b> <?php echo $data->current_url ?><br>
Referrer: <?php echo $data->referrer ?><br>
<b>Browser:</b> <?php echo $data->browser ?><br>
Mobile: <?php echo $data->mobile ?><br>
<b>Platform:</b> <?php echo $data->platform ?><br>
<b>User Agent:</b> <?php echo $data->user_agent ?>
</p>
</div>
</div>
<?php } } ?>
<?php echo $this->pagination->create_links(); ?>
你说你的uid
是$this->uri->segment(4);
。如果那是 segment(4)
,那么在你的控制器中,你说 $config["uri_segment"] = 4;
如果您的 URL 类似于:http://example.com/profile/view/1/10
其中 1
是 uid
,那么您应该更改 [=15= 中的 4
] 到 5
.
所以我会替换这一行(在你的控制器中):
$config["uri_segment"] = 4;
与:
$config["uri_segment"] = 5;