codeigniter 3自定义分页引导程序

时间:2016-12-13 05:44:08

标签: php codeigniter-3

如何使用bootstrap 4自定义codeigniter链接?

我正在尝试,但我没有运气链接。

感谢。

public function index($start=0)
{
    if (!$this->session->userdata('user_id'))
    {
        redirect(base_url().'admin/login');
    }
    $this->load->model('M_Articulos');
    $data['posts'] = $this->M_Articulos->select_posts(1, $start);

    //paginacion
    $this->load->library('pagination');
    $config['base_url'] = base_url()."admin/index";
    $config['total_rows'] = $this->M_Articulos->get_post_count();
    $config['per_page'] = 1;
    //paginacion estilos con bootstrap

    $this->pagination->initialize($config);
    $data['pages'] = $this->pagination->create_links(); //Links of pages

    $this->load->view('admin/layouts/header');
    $this->load->view('admin/modules/main', $data);
    $this->load->view('admin/layouts/footer');
}

1 个答案:

答案 0 :(得分:0)

如果您使用的是codeigniter-3, 检查分页库,如果您使用的是默认分页库,

您需要根据您的要求在create_links()函数中进行更改。

可自定义的代码在这里:

// Render the pages
    if ($this->display_pages !== FALSE)
    {
        // Write the digit links
        for ($loop = $start - 1; $loop <= $end; $loop++)
        {
            $i = ($this->use_page_numbers) ? $loop : ($loop * $this->per_page) - $this->per_page;

            $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, $loop);

            if ($i >= $base_page)
            {
                if ($this->cur_page === $loop)
                {
                    // Current page
                    $output .= $this->cur_tag_open.$loop.$this->cur_tag_close;
                }
                elseif ($i === $base_page)
                {
                    // First page
                    $output .= $this->num_tag_open.'<a href="'.$first_url.'"'.$attributes.$this->_attr_rel('start').'>'
                        .$loop.'</a>'.$this->num_tag_close;
                }
                else
                {
                    $append = $this->prefix.$i.$this->suffix;
                    $output .= $this->num_tag_open.'<a href="'.$base_url.$append.'"'.$attributes.'>'
                        .$loop.'</a>'.$this->num_tag_close;
                }
            }
        }
    }

    // Render the "next" link
    if ($this->next_link !== FALSE && $this->cur_page < $num_pages)
    {
        $i = ($this->use_page_numbers) ? $this->cur_page + 1 : $this->cur_page * $this->per_page;

        $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, $this->cur_page + 1);

        $output .= $this->next_tag_open.'<a href="'.$base_url.$this->prefix.$i.$this->suffix.'"'.$attributes
            .$this->_attr_rel('next').'>'.$this->next_link.'</a>'.$this->next_tag_close;
    }

    // Render the "Last" link
    if ($this->last_link !== FALSE && ($this->cur_page + $this->num_links + ! $this->num_links) < $num_pages)
    {
        $i = ($this->use_page_numbers) ? $num_pages : ($num_pages * $this->per_page) - $this->per_page;

        $attributes = sprintf('%s %s="%d"', $this->_attributes, $this->data_page_attr, $num_pages);

        $output .= $this->last_tag_open.'<a href="'.$base_url.$this->prefix.$i.$this->suffix.'"'.$attributes.'>'
            .$this->last_link.'</a>'.$this->last_tag_close;
    }