我想在提交(搜索框)后保留该值,因此我使用set_value();
我保留了价值
但之后我点击了指向下一页的链接(分页),我无法保留该值,因为我没有点击提交按钮,所以如何在不点击提交按钮的情况下保留该值再次?
查看
<?php
$attr_form= array(
'class' => 'form-horizontal',
'role' => 'form'
);
echo form_open('dipanddig/search', $attr_form);
echo '<div class="input-group search-box-width">';
echo form_input('search', set_value('search'), 'class="form-control search-box-height"');
echo '<span class="input-group-btn">';
echo '<button type="submit" class="btn btn-default search-box-height">';
echo '<span class="glyphicon glyphicon-search">';
echo '</span>';
echo '</button>';
echo '</span>';
echo form_close();
echo '</div>';
?>
控制器
function search(){
$this->load->library('pagination');
$data['base_url'] = 'http://localhost:100/dipanddig/dipanddig/search';
$data['total_rows'] = $this->db->select('name')->like('name', $this->input->post('search'))->get('clothes')->num_rows();
$data['per_page'] = 1;
$data['num_links'] = 2;
$data['records'] = $this->db->select('id,price,name')->like('name', $this->input->post('search'))->get('clothes',$data['per_page'],$this->uri->segment(3));
$this->pagination->initialize($data);
$this->load->view('products', $data);
}
非常感谢你帮助我。
答案 0 :(得分:1)
在搜索表单中添加“清除”按钮
function search()
{
$this->load->library('pagination');
// add this
$this->load->library('session');
if ($this->input->post('search')) {
$this->session->set_userdata('search' => $this->input->post('search'));
}
$data['base_url'] = 'http://localhost:100/dipanddig/dipanddig/search';
$data['total_rows'] = $this->db->select('name')->like('name', $this->session->userdata('search'))->get('clothes')->num_rows();
$data['per_page'] = 1;
$data['num_links'] = 2;
$data['records'] = $this->db->select('id,price,name')->like('name', $this->session->userdata('search'))->get('clothes',$data['per_page'],$this->uri->segment(3));
$this->pagination->initialize($data);
$this->load->view('products', $data);
}
HTTP是无状态协议。尽量熟悉惯例。
PS。您还可以从会话中设置表单值以获得更好的用户权限