当我在分页上单击下一个数字时,Link 仍然在数字 1 处处于活动状态
When I click to the next number on pagination, Link active still at number 1
我的控制器功能
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class News extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('news_media');
$this->load->library('pagination');
}
public function index()
{
$config['base_url'] = base_url()."secret/news/index";
$config['total_rows'] = $this->news_media->getCount();
$config['per_page'] = 3;
$this->pagination->initialize($config);
$page = ($this->uri->segment(4))?$this->uri->segment(4):0;
$data = array();
$data['allnews'] = $this->news_media->get($config['per_page'],$page);
$data['links'] = $this->pagination->create_links();
$html = array();
$html['title'] = "Setting";
$html['head'] = $this->load->view('secret/template/header',null, true);
$html['top'] = $this->load->view('secret/template/top',null, true);
$html['menu'] = $this->load->view('secret/template/menu',null, true);
$html['content'] = $this->load->view('secret/news/news',$data, true);
$html['js'] = $this->load->view('secret/template/js',null, true);
$this->load->view('secret/template/template',$html);
}
}
问题是我有分页 1,2,并且在每一页中我显示 3 个项目。
当我点击第二页时 link 仍然处于第 1 页。如何修复它?
谢谢之前
在分页配置设置中添加uri_segment
:
$config['base_url'] = base_url()."secret/news/index";
$config['total_rows'] = $this->news_media->getCount();
$config['per_page'] = 3;
$config["uri_segment"] = 4;
$this->pagination->initialize($config);
希望本文能帮助您解决这个问题。看看 documentation 上的解释。
$config['uri_segment'] = 3;
The pagination function automatically determines which segment of your URI contains the page number. If you need something different you can specify it.
我的控制器功能
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class News extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('news_media');
$this->load->library('pagination');
}
public function index()
{
$config['base_url'] = base_url()."secret/news/index";
$config['total_rows'] = $this->news_media->getCount();
$config['per_page'] = 3;
$this->pagination->initialize($config);
$page = ($this->uri->segment(4))?$this->uri->segment(4):0;
$data = array();
$data['allnews'] = $this->news_media->get($config['per_page'],$page);
$data['links'] = $this->pagination->create_links();
$html = array();
$html['title'] = "Setting";
$html['head'] = $this->load->view('secret/template/header',null, true);
$html['top'] = $this->load->view('secret/template/top',null, true);
$html['menu'] = $this->load->view('secret/template/menu',null, true);
$html['content'] = $this->load->view('secret/news/news',$data, true);
$html['js'] = $this->load->view('secret/template/js',null, true);
$this->load->view('secret/template/template',$html);
}
}
问题是我有分页 1,2,并且在每一页中我显示 3 个项目。 当我点击第二页时 link 仍然处于第 1 页。如何修复它?
谢谢之前
在分页配置设置中添加uri_segment
:
$config['base_url'] = base_url()."secret/news/index";
$config['total_rows'] = $this->news_media->getCount();
$config['per_page'] = 3;
$config["uri_segment"] = 4;
$this->pagination->initialize($config);
希望本文能帮助您解决这个问题。看看 documentation 上的解释。
$config['uri_segment'] = 3;
The pagination function automatically determines which segment of your URI contains the page number. If you need something different you can specify it.