Codeigniter分页 - 第2页的数组变量为空

时间:2016-11-14 08:10:12

标签: php arrays codeigniter pagination

我正在搜索搜索页面,因为搜索基于数组$s_id。一旦我搜索了一些输入值,搜索结果就会与分页链接一起显示。(分页链接也很完美。如果我有6个结果,per_page是2,那么它显示3页链接 )。

现在我的问题是,一旦我点击第2页显示空白页面,我尝试在第2页上打印$s_id,然后数组显示为Array ( [0] => ),这意味着在第2页{{1有一些其他的价值。

CONTROLLER

$s_id

模型

public function index()
        {        
        $s_id = array();
        $skills = $this->input->post('skills');
        //pagination settings
        $config['per_page'] = 2;
        $config['base_url'] = site_url('search');
        $config['first_url'] = site_url('search/').'1';
        $config['use_page_numbers'] = TRUE;
        $config['num_links'] = 3;
        $config['uri_segment'] = 2;
        $config['cur_tag_open'] = "<li><span><b>";
        $config['cur_tag_close'] = "</b></span></li>";
        $config['full_tag_open'] = '<ul class="pagination pagination-large">';
        $config['full_tag_close'] = '</ul>';
        $config['prev_tag_open'] = '<li>'; 
        $config['prev_tag_close'] = '</li>';
        $config['next_tag_open'] = '<li>';
        $config['next_tag_close'] = '</li>';
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';
        $config['cur_tag_open'] = '<li class="active"><a>';
        $config['cur_tag_close'] = '</a></li>';

        $page = $this->uri->segment(2);

        $limit_end = ($page * $config['per_page']) - $config['per_page'];
        if ($limit_end < 0){
            $limit_end = 0;
        }

        if($skills == TRUE || $this->uri->segment(2) == TRUE){
            $s_id = explode(',', $skills[0]);
            if($s_id){
              $filter_session_data['skill_id_selected'] = $s_id;
            }else{
              $s_id = $this->session->userdata('skill_id_selected');
            }
            $data['skill_id_selected'] = $s_id;
            if(isset($filter_session_data)){
                $this->session->set_userdata($filter_session_data);
            }

            // print_r($s_id); exit();                     //commented
            // $s_id = array('2D Design','3D Design');     //commented

            $data['count_user'] =  $this->m_results->count_users($s_id);
            $config['total_rows'] = $data['count_user'];
            $data['freelancers'] = $this->m_results->search_people($s_id,$config['per_page'],$limit_end);
            $this->pagination->initialize($config);
            $this->load->view('include/header');
            $this->load->view('search',$data);
            $this->load->view('include/footer');
        }else{  
            $this->load->view('include/header');
            $this->load->view('search');
            $this->load->view('include/footer');
        }
}  

请帮我解决这个问题。

1 个答案:

答案 0 :(得分:0)

$skills = $this->input->post('skills'); - 很重要。使用post方法提交表单时,您将获得此值。对于next page,您必须使用skills提交表单并输入页码,而不是简单地重定向网址。

将表单提交方式更改为GET。因此,您可以轻松地将具有搜索字段值的网址轻松重定向到下一页和上一页。