【发布时间】:2014-12-14 11:25:33
【问题描述】:
我有一个 codeigniter 搜索表单,其中包括一个下拉列表(汽车)和一个复选框数组(汽车类型)。我使用 POST 方法从数据库中获取值,但是 post 方法与分页冲突,所以我决定使用 GET 方法。但现在我的“if”语句不起作用,它返回给我“else”场景(即“search_nok”页面,带有“请选择您的搜索选项”消息)。请您检查我的代码并帮助我找出错误。
这是我的控制器
public function search($offset = 0) {
$limit = 5;
$this->load->library('form_validation');
$this->load->model('model_x');
$this->form_validation->set_rules('car', 'Car','required');
$this->form_validation->set_rules('types', 'Car Type','required');
if($this->form_validation->run()) {
$car= $this->input->get('car');
$types = $this->input->get('types');
$this->load->library('pagination');
$config['base_url'] = 'http://localhost/abc/cont/search/';
// 'http://localhost/abc' is my base url
$config['total_rows'] = 14;
$config['per_page'] = 5;
$data['pagination'] = $this->pagination->initialize($config);
if ($this->model_x->did_search($car, $types, $limit, $offset)){
$data["results"] = $this->model_x->did_search($car, $types, $limit, $offset);
$this->load->view("search_ok",$data);
}
}
else
{
$data['message'] = 'Please select your options.';
$this->load->view("search_nok",$data);
}
}
【问题讨论】:
-
不,这是一个不同的问题
-
同样的问题。您正在尝试验证通过
$_GET收到的表单。关于 SO 至少有 3 个相同的问题。 -
不,我正在尝试使用 codeigniter 分页显示我的搜索结果。使用get还是post都没有关系,但是当我尝试验证结果时,它不适用于第二页。
标签: php codeigniter get pagination