当我点击分页时的下一个数字时,链接激活仍然在数字1

时间:2022-11-21 15:23:13

My controller function

我的控制器功能

<?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);
    }
}

Problem is that I have pagination 1,2 and in every page I display 3 items. When I click second page link active still in number 1. How to fix its?

问题是我有分页1,2在每个页面我显示3项。当我点击第二页链接激活仍然在数字1。如何解决它?

Thank before

1 个解决方案

#1


Add uri_segment in you pagination config settings:

在您的分页配置设置中添加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);

Hope this will help you to resolve this problem. Take a look on documentation that explain it.

希望这可以帮助您解决此问题。看看解释它的文档。

$config['uri_segment'] = 3;

$ 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.

分页功能自动确定URI的哪个部分包含页码。如果您需要不同的东西,可以指定它。

#1


Add uri_segment in you pagination config settings:

在您的分页配置设置中添加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);

Hope this will help you to resolve this problem. Take a look on documentation that explain it.

希望这可以帮助您解决此问题。看看解释它的文档。

$config['uri_segment'] = 3;

$ 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.

分页功能自动确定URI的哪个部分包含页码。如果您需要不同的东西,可以指定它。