Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Codeigniter 代码点火器上的搜索和分页_Codeigniter_Search_Pagination - Fatal编程技术网

Codeigniter 代码点火器上的搜索和分页

Codeigniter 代码点火器上的搜索和分页,codeigniter,search,pagination,Codeigniter,Search,Pagination,伙计们 我尝试使用分页创建搜索。我可以做到,当我转到第二页时并没有问题,但当我转到第三页时,数据丢失了。 请帮帮我。这是我的控制器代码: function fast_search() { $data = array( 'reason' => $this->input->post('reason'), 'shahr' => $this->input->post('shahr'),

伙计们

我尝试使用分页创建搜索。我可以做到,当我转到第二页时并没有问题,但当我转到第三页时,数据丢失了。 请帮帮我。这是我的控制器代码:

function fast_search() {

    $data = array(
        'reason'           => $this->input->post('reason'),
        'shahr'            => $this->input->post('shahr'),
        'file_type'        => $this->input->post('file_type'),
        'region'           => $this->input->post('region'),
        'neighbourhood'    => $this->input->post('neighbourhood'),
        'under_build_area' => $this->input->post('under_build_area'),
        'user_type'        => $this->input->post('user_type')
    );

    $this->session->set_flashdata($data);

    /*-------------------------------------------------------*/
    $page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;

    if ($page == 0) 
    {
        $config = array();
        $config['base_url']    = base_url() . 'file/fast_search/page';
        $config['per_page']    = 9;
        $config['uri_segment'] = 4;
        $config['total_rows']  = count($this->file_model->fast_search($data));
        $this->pagination->initialize($config);

        $data['results'] = $this->file_model->fast_search($data, $config['per_page'], $page);
        $data['links']   = $this->pagination->create_links();

    } else {

        $this->session->keep_flashdata('reason');
        $this->session->keep_flashdata('shahr');
        $this->session->keep_flashdata('file_type');
        $this->session->keep_flashdata('region');
        $this->session->keep_flashdata('neighbourhood');
        $this->session->keep_flashdata('under_build_area');
        $this->session->keep_flashdata('user_type');

        $result_data = array(
            'reason'           => $this->session->flashdata('reason'),
            'shahr'            => $this->session->flashdata('shahr'),
            'file_type'        => $this->session->flashdata('file_type'),
            'region'           => $this->session->flashdata('region'),
            'neighbourhood'    => $this->session->flashdata('neighbourhood'),
            'under_build_area' => $this->session->flashdata('under_build_area'),
            'user_type'        => $this->session->flashdata('user_type')
        );

        $config = array();
        $config['base_url']    = base_url() . 'file/fast_search/page';
        $config['per_page']    = 9;
        $config['uri_segment'] = 4;
        $config['total_rows']  = count($this->file_model->fast_search($result_data));
        $this->pagination->initialize($config);

        //$this->dvd($result_data);
        $data['results'] = $this->file_model->fast_search($result_data, $config['per_page'], $page);
        $data['links']   = $this->pagination->create_links();
    }

    /*-------------------------------------------------------*/

    //$this->dvd($data['links']);

    if ($data['results'] != FALSE) 
    {
        $data['agency_nums']      = $this->user_model->get_registered_agency();
        $data['updated_agencies'] = $this->user_model->get_uplated_agencies();
        $data['count_files']      = $this->file_model->count_files();

        $this->load->view('fast_search', $data);
        //return $data;
    } else {
        $data['error']            = 'No Result !';
        $data['agency_nums']      = $this->user_model->get_registered_agency();
        $data['updated_agencies'] = $this->user_model->get_uplated_agencies();
        $data['count_files']      = $this->file_model->count_files();
        $this->load->view('fast_search', $data);
    }
}
我使用的会话功能如下: $this->session->set_flashdata($data);
$this->session->keep_flashdata('reason')

您好,我非常喜欢net.tuts关于在CI中搜索的教程,它非常好,您不需要使用会话来保存和检索搜索数据,您需要扩展您的输入类,它将在数据库中保存关键字和搜索条件,并为您提供保存的记录的id,您可以在分页中使用这些id。看看这个非常棒的教程


如果您在点击下一页时将会话设置为空,因为$data不是数据(post只发送一个),我认为您必须设置这样的条件

    $is_search =  $this->input->post('search'); // name button search
    if (!array_filter($data) && $is_search===false) { // check array is empty and no search value (only submit form have search name)
           $data = array(
                 'reason'           => $this->session->userdata('reason'),
                 'shahr'            => $this->session->userdata('shahr'),
                 'file_type'        => $this->session->userdata('file_type'),
                 'region'           => $this->session->userdata('region'),
                 'neighbourhood'    => $this->session->userdata('neighbourhood'),
                 'under_build_area' => $this->session->userdata('under_build_area'),
                 'user_type'        => $this->session->userdata('user_type')
           );
    } else {
           $this->session->set_userdata( $data ); // create new session
    }
/*-------------------------------------------------------*/
    $page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;

我建议使用
set\u userdata()
而不是
flashdata()
。这样,您就可以在每个页面请求上使用搜索变量,而不必使用
keep\u flashdata()