分页 - 每页仍然是第一页Codeigniter

时间:2013-10-20 12:00:30

标签: php codeigniter url pagination

我的CI出了问题。 我正在使用CI分页,但是当我到第2页/第3页时......第一页仍在进行中。 每当我更改页面时,内容也会发生变化,但第一页仍标记为1 功能URL是:

URI->段(4) www.site.com/controller/function/index/1(page number)

功能:

$this->load->helper("url");
        $limite = 6;
        if ($this->uri->segment(4) == ""):
            $data['start'] = 0;
        else:
            $data['start'] = $this->uri->segment(4);
            $data['start'] = ($data['start']-1)*$limite;
        endif;

        //Carregar a livraria paginação
        $this->load->library('pagination');
        //URL Base
        $config['base_url']     =   base_url().'item_shop/armaduras/index/';
        //Total de registos
        $config['total_rows']   =   $this->item_shop_model->contar_armaduras($limite,$data['start']);
        //Numero de links
        $config['num_links']    =   5;
        // Segmento que conterá o parâmetro de incremento
        $config['uri_sigments'] =   3;
        $config['per_page']     =   $limite;
        $config['first_page']   =   1;

        // Configuracoes de estilo da url
        $config['first_link'] = '<<';
        $config['last_link'] = '>>';
        $config['next_link'] = '>';
        $config['prev_link'] = '<';
        $config['cur_tag_open'] = '<span class="current">';
        $config['cur_tag_close'] = '</span>';
        $config['use_page_numbers'] = TRUE;     

        // Iniciamos as configuracoes e criamos o link para o acesso
        $this->pagination->initialize($config);
        $data['pagination']     =   $this->pagination->create_links();
        $data['items']          =   $this->item_shop_model->select_all_armaduras($limite,$data['start']);
        $data['title']          =   "HeroM2 Servidor Privado de Metin2";
        $this->load->view('shop-2',$data);

当我使用索引功能控制器时,它完美地工作:

URI-&GT;链段(3) www.site.com/controller/index/1

索引功能:

$this->load->helper("url");
        //Limite de registos
        $limite = 6;
        if ($this->uri->segment(3) == ""):
            $data['start'] = 0;
        else:
            $data['start'] = $this->uri->segment(3);
            $data['start'] = ($data['start']-1)*$limite;
        endif;

        //Carregar a livraria paginação
        $this->load->library('pagination');
        //URL Base
        $config['base_url']     =   base_url().'item_shop/index/';
        //Total de registos
        $config['total_rows']   =   $this->item_shop_model->contar_espadas($limite,$data['start']);
        //Numero de links
        $config['num_links']    =   5;
        // Segmento que conterá o parâmetro de incremento
        $config['uri_sigments'] =   3;
        $config['per_page']     =   $limite;
        $config['first_page']   =   1;

        // Configuracoes de estilo da url
        $config['first_link'] = '<<';
        $config['last_link'] = '>>';
        $config['next_link'] = '>';
        $config['prev_link'] = '<';
        $config['cur_tag_open'] = '<span class="current">';
        $config['cur_tag_close'] = '</span>';
        $config['use_page_numbers'] = TRUE;     

        // Iniciamos as configuracoes e criamos o link para o acesso
        $this->pagination->initialize($config);
        $data['pagination']     =   $this->pagination->create_links();
        $data['items'] = $this->item_shop_model->select_all_espadas($limite,$data['start']);
        $data['title'] = "HeroM2 Servidor Privado de Metin2";
        $this->load->view('shop-1',$data);

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

当网址为www.site.com/controller/function/index/1时,uri_segment配置应为4