4

彼ら

ページネーションで検索を作成しようとしています。2ページ目に行くときは問題ありませんが、3ページ目に行くとデータが失われます。私を助けてください。これはコントローラーの私のコードです:

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');

4

2 に答える 2

4

こんにちは、CI での検索に関する net.tuts のこのチュートリアルが本当に気に入っています。検索データの保存と取得にセッションを使用する必要はありません。入力クラスを拡張する必要があり、キーワードと検索条件をデータベースに保存します。あなたとページネーションで使用できるその保存されたレコードの id は、この本当に素晴らしいチュートリアルを見てください。

CI 検索とページネーション

于 2012-12-15T16:46:16.590 に答える