在Codeigniter中搜索时按下的文档已过期

时间:2016-11-26 10:18:23

标签: php codeigniter cache-expiration

我有一个程序,我有搜索代码。当我搜索它时会显示一个包含搜索结果的页面。该页面将显示一些可以单击的内容。当我点击该内容时,它将显示产品的详细信息。从这个详细信息页面,当我在浏览器中单击它时,它应该返回到搜索结果页面,但我在此处获得文档过期。当我重新加载文档已过期的页面时,它将再次显示搜索结果。我使用的是codeigniter。我尝试了一些我找到的代码,但它仍然无效。这是我的问题。请帮我。谢谢。

控制器

public function search_bar($keyWordRestoran=NULL, $page=NULL, $orderBy=NULL)
        {
            if($this->session->userdata('logged_in'))
            {
                $session_data = $this->session->userdata('logged_in');
                $data['nama'] = $session_data['nama'];
                $data['id'] = $session_data['id_user'];
                $data['tipeUser'] = $session_data['tipe_user'];

            }
            else{
                $data['nama'] = "";
                $data['id'] = "0";
                $data['tipeUser']="";
            }
            $data['url_image'] = $this->imageUrl;
            $keyWordRestoran_ip = $this->input->post('input-keyword');
            if($keyWordRestoran_ip=="")
            {
                $session_data = $this->session->userdata('keyword_resto');
                $keyWordRestoran = $session_data['keyword_resto'];
            }
            else{
                $sess_array2 = array();
                $sess_array2 = array(
                    'keyword_resto' => $keyWordRestoran_ip
                    );
                $this->session->set_userdata('keyword_resto', $sess_array2);
                $session_data = $this->session->userdata('keyword_resto');
                $keyWordRestoran = $session_data['keyword_resto'];
            }

            $data['kunci_cari'] = $keyWordRestoran;

            $config['base_url'] = base_url().'/home_controller/search_bar/'.$keyWordRestoran;

            $data['jmlh_rows'] = $this->restoran->GetRestoran_search($keyWordRestoran);

            $total_row = $data['jmlh_rows']->num_rows();

            $config["total_rows"] = $total_row;
            $config["per_page"] = 8;
            $config['cur_tag_open'] = '&nbsp;<a class="current">';
            $config['cur_tag_close'] = '</a>';
            $config['next_link'] = 'Next';
            $config['prev_link'] = 'Previous';

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

            $str_links = $this->pagination->create_links();
            $data["links"] = explode('&nbsp;',$str_links );
            $data["dataRestoran"] = $this->restoran->GetRestoranPerPage_search($config["per_page"], $keyWordRestoran, $page, $orderBy);
            $data['url_image'] = $this->imageUrl;
            $data['data_kategori'] = $this->jenismakanan->Getjenismakanan();
            $this->load->view('food-type_search', $data);
        }

搜索视图

<div class="header-bottom">
    <div class="col-xs-1">
        <button class="toggle-button"></button>
    </div>
    <div class="col-xs-11">
    <?php echo form_open('home_controller/search_bar');?>
    <div class="search">
    <form method="GET">
        <input type="text" id= "input-keyword" name="input-keyword" placeholder="Search ..." value="<?php echo set_value('input-keyword')?>" >
        <input type="submit" value="">  
    </form><?php echo form_close(); ?> 
    </div>
    </div>
<div class="clearfix"> </div>

1 个答案:

答案 0 :(得分:2)

你已经两次包括表格。一个表单是使用<?php echo form_open('home_controller/search_bar');?>创建的,另一个是静态的html.So需要删除静态html表单并且for_open是可以的。在form_open中,您需要指定方法get。这里我更新了这段代码 -

<div class="header-bottom">
    <div class="col-xs-1">
        <button class="toggle-button"></button>
    </div>
    <div class="col-xs-11">
    <?php echo form_open('home_controller/search_bar',array('method' => 'get'));?>
    <div class="search">

        <input type="text" id= "input-keyword" name="input-keyword" placeholder="Search ..." value="<?php echo set_value('input-keyword')?>" >
        <input type="submit" value="">  
    </div>
   <?php echo form_close(); ?> 
    </div>
<div class="clearfix"> </div>

在search_bar函数的控制器中,现在使用get方法获取表单值,而不是像

那样发布
$keyWordRestoran_ip = $this->input->get('input-keyword');