如何在没有配置的情况下设置分页链接的样式 - codeigniter

时间:2015-05-07 09:25:19

标签: codeigniter pagination

我有以下分页风格

                            <ul class="pagination">
                            <li><a href="#"><i class="fa fa-long-arrow-left"></i>Previous Page</a></li>
                            <li class="active"><a href="#">1</a></li>
                            <li><a href="#">2</a></li>
                            <li><a href="#">3</a></li>
                            <li><a href="#">4</a></li>
                            <li><a href="#">Next Page<i class="fa fa-long-arrow-right"></i></a></li>
                            </ul><!--/.pagination--> 

我想在不使用config

的情况下使上述静态代码动态化
<ul class="pagination">

<?php echo $this->pagination->create_links(); ?>

</ul><!--/.pagination--> 

控制器

        $config['full_tag_open']    = "<ul class='pagination'>";
        $config['full_tag_close']   = "</ul>";
        $config['num_tag_open']     = '<li>';
        $config['num_tag_close']    = '</li>';
        $config['cur_tag_open']     = "<li class='disabled'><li class='active'><a href='#'>";
        $config['cur_tag_close']    = "<span class='sr-only'></span></a></li>";
        $config['next_tag_open']    = "<li>";
        $config['next_tagl_close']  = "</li>";
        $config['prev_tag_open']    = "<li>";
        $config['prev_tagl_close']  = "</li>";
        $config['first_tag_open']   = "<li>";
        $config['first_tagl_close'] = "</li>";
        $config['last_tag_open']    = "<li>";
        $config['last_tagl_close']  = "</li>";
        $this->pagination->initialize($config); 

3 个答案:

答案 0 :(得分:8)

好的,我试过,这个控制器代码工作正常

    $config['full_tag_open'] = "<ul class='pagination'>";
    $config['full_tag_close'] = '</ul>';
    $config['num_tag_open'] = '<li>';
    $config['num_tag_close'] = '</li>';
    $config['cur_tag_open'] = '<li class="active"><a href="#">';
    $config['cur_tag_close'] = '</a></li>';
    $config['prev_tag_open'] = '<li>';
    $config['prev_tag_close'] = '</li>';
    $config['first_tag_open'] = '<li>';
    $config['first_tag_close'] = '</li>';
    $config['last_tag_open'] = '<li>';
    $config['last_tag_close'] = '</li>';



    $config['prev_link'] = '<i class="fa fa-long-arrow-left"></i>Previous Page';
    $config['prev_tag_open'] = '<li>';
    $config['prev_tag_close'] = '</li>';


    $config['next_link'] = 'Next Page<i class="fa fa-long-arrow-right"></i>';
    $config['next_tag_open'] = '<li>';
    $config['next_tag_close'] = '</li>';


    $this->pagination->initialize($config); 

查看

 <?php echo $this->pagination->create_links(); ?>

答案 1 :(得分:1)

在你的控制器中添加此配置。

               $config['full_tag_open'] = "<ul class='pagination'>";
                $config['full_tag_close'] = '</ul>';
                $config['num_tag_open'] = '<li>';
                $config['num_tag_close'] = '</li>';
                $config['cur_tag_open'] = '<li class="active"><a href="#">';
                $config['cur_tag_close'] = '</a></li>';
                $config['prev_tag_open'] = '<li>';
                $config['prev_tag_close'] = '</li>';
                $config['first_tag_open'] = '<li>';
                $config['first_tag_close'] = '</li>';
                $config['last_tag_open'] = '<li>';
                $config['last_tag_close'] = '</li>';

                $config['next_link'] = 'Next Page';
                $config['next_tag_open'] = '<li><i class="fa fa-long-arrow-right"></i>';
                $config['next_tag_close'] = '</li>';

                $config['prev_link'] = 'Previous Page';
                $config['prev_tag_open'] = '<li><i class="fa fa-long-arrow-left"></i>';
                $config['prev_tag_close'] = '</li>';
                $this->pagination->initialize($config); 

并且在您看来只是回声分页

<?php echo $this->pagination->create_links(); ?>

删除ul

答案 2 :(得分:0)

控制器

public function moreNews($pid = 0){ $config['base_url'] =
    base_url('index.php/MainController/morenews'); $config['total_rows']
    = 200; $config['per_page'] = 5; $config['full_tag_open'] = '<ul class="pagination">'; $config['full_tag_close'] = '</ul>';
    $config['first_tag_open'] = "<li class='page-item'>";
    $config['first_tag_close'] = "</li>"; $config['prev_tag_open'] =
    "<li class='page-item'>"; $config['prev_tag_close'] = "</li>";
    $config['next_tag_open'] = "<li class='page-item'>";
    $config['next_tag_close'] = "</li>"; $config['last_tag_open'] = "<li
    class='page-item'>"; $config['last_tag_close'] = "</li>";
    $config['cur_tag_open'] = "<li class='page-item'><a class='page-link
    active' href=''>"; $config['cur_tag_close'] = "</a></li>";
    $config['num_tag_open'] = "<li class='page-item'>";
    $config['num_tag_close'] = "</li>"; $config['attributes'] =
    array('class' => 'page-link');
    $this->pagination->initialize($config); $data['pagination'] =
    $this->pagination->create_links(); $data['news'] =
    $this->MainModel->paginationpage($pid); $data['news']=
    $this->MainModel->get_news(); //echo '<pre>'; // print_r($data);
    $this->load->view('morenews', $data); }`.

模型

function paginationpage($pid){ $count=1;
    $this->db->select('*')->from('_news')->limit($count, $pid,
    $pid+$count); $query=$this->db->get(); return
    $query->result_array(); }`.