在 Codeigniter 中搜索时文档过期返回浏览器被按下
Document Expired Back Browser Pressed When Searching in 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'] = ' <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(' ',$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>
您包含了两次表格。一种形式是使用 <?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 方法而不是像
那样的 post 获取表单值
$keyWordRestoran_ip = $this->input->get('input-keyword');
我有一个程序,其中包含搜索代码。当我搜索时,它会显示一个包含搜索结果的页面。该页面将显示一些可以单击的内容。当我单击该内容时,它会显示产品的详细信息。从这个详细信息页面,当我在浏览器中单击返回时,它应该返回到搜索结果页面,但我在这里得到的文档已过期。当我重新加载文档已过期的页面时,它将再次显示搜索结果。我正在使用代码点火器。我尝试了一些我发现的代码,但它仍然无法正常工作。那是我的问题。请帮我。谢谢。
控制器
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'] = ' <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(' ',$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>
您包含了两次表格。一种形式是使用 <?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 方法而不是像
那样的 post 获取表单值$keyWordRestoran_ip = $this->input->get('input-keyword');