分页代码在codeigniter中不起作用

时间:2016-06-03 10:21:10

标签: php codeigniter

分页代码在codeigniter中不起作用,它会转到下一页,但页面上什么都不能显示?

控制器代码就像这样

public function search_by_keywords()
{
     //library added
     $this->load->library('pagination');
     //model loaded
     $this->load->model('free/search_resource_model');
     $config["base_url"] = base_url().'free/keyword/search_by_keywords';
     $config["total_rows"] = 5;
     $config["per_page"] = 4;
     $config['uri_segment'] = 4; 
     $config['use_page_numbers'] = TRUE;
     $this->pagination->initialize($config);
     $page =$this->uri->segment(4);
     $data["reso_list"] =   $this->search_resource_model->serch_with_kw($config["per_page"], $page);
     //create link 
     $data["links"] = $this->pagination->create_links();
     $data["title"] = 'Search Resources by Keywords ';
}

2 个答案:

答案 0 :(得分:1)

试试这个

function search_by_keywords($offset = null)
    {    
        $admin_session_data= $this->session->userdata('user_logged_in');

        // Load models/libraries/helpers
        $this->load->model('admin/provider_model');
        $this->load->library('pagination');
        $this->load->helper('url');

        // Pagination config
        $config['base_url'] = base_url().'free/keyword/search_by_keywords';
        $config['total_rows'] = 5;
        $config['per_page'] = 3;
        // $config['creat_link'] = 1; <-- This is not a valid option
        $config['first_link'] = 'First';
        $config['last_link'] = 'Last';

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

        // If the pagination library doesn't recognize the current page add:
        $this->pagination->cur_page = $offset;

        $data['list']= $this->provider_model->listproviders($config['per_page'],$offset);


         $page =$this->uri->segment(4);
         $data["reso_list"] =   $this->search_resource_model->serch_with_kw($config["per_page"], $page);a
         //create link 
         $data["links"] = $this->pagination->create_links();
         $data["title"] = 'Search Resources by Keywords ';
    }

答案 1 :(得分:0)

使用此:

function page_custom($total_page,$base_url,$per_page){

    $config['first_link'] = 'First';
    $config['first_tag_open'] = '<li>';
    $config['first_tag_close'] = '</li>';
    $config['last_link'] = 'Last';
    $config['last_tag_open'] = '<li>';
    $config['last_tag_close'] = '</li>';
    $config['prev_link'] = '<i class="fa fa-chevron-left"></i>';
    $config['prev_tag_open'] = '<li>';
    $config['prev_tag_close'] = '</li>';
    $config['num_tag_open'] = '<li>';
    $config['num_tag_close'] = '</li>';
    $config['cur_tag_open'] = '<li class="active"><a href="javascript:void(0)">';
    $config['cur_tag_close'] = '</a></li>';
    $config['full_tag_open'] = '<ul class="pagination">';
    $config['full_tag_close'] = '</ul>';
    $config['next_link'] = '<i class="fa fa-chevron-right"></i>';
    $config['next_tag_open'] = '<li>';
    $config['next_tag_close'] = '</li>';
    $config['base_url'] = $base_url; 
    $config['total_rows'] = $total_page;
    $config['per_page'] = $per_page;        
    $config['suffix'] = '?'.http_build_query($_GET, '', "&"); 
    return $config;
}