我正在尝试制作搜索引擎,但是当我点击搜索按钮时,它会转到404页面。以下是我的观点:
<aside class="widget">
<h5>SEARCH BLOG</h5>
<form class="form-inline search" role="search" action="<?php echo site_url('blog/search/');?>" method = "post">
<div class="form-group">
<div class="input-group">
<input name="search" type="text" class="form-control" id="search" placeholder="Search">
<div class="input-group-addon">
<button type="submit" class="btn btn-default"><i class="fa fa-search"></i></button>
</div>
</div>
</div>
</form>
</aside>
这是我的模特:
function blog_search($keyword) {
$this->db->select('*');
$this->db->from('news');
$this->db->like('title_rus',$keyword);
$this->db->like('body_rus',$keyword);
$query = $this->db->get();
return $query->result();
}
这是我的控制器:
function search() {
$keyword = $this->input->post('search');
$data['random_courses'] = $this->courses_model->get_random_course();
$data['category'] = $this->news_model->get_category_for_sidebar ();
$data['blog'] = $this->news_model->blog_search($keyword);
echo '<pre>';
print_r($data['blog']);
echo '</pre>'; die();
$this->load->view('templates/header');
$this->load->view('blog/blog', $data);
$this->load->view('templates/footer');
}
答案 0 :(得分:0)
将$route["blog/search/(:any)"] = 'blog/search/$1'
更改为$route["blog/search"] = 'blog/search'
,然后重试。我不认为查询参数会在您的路线中计算为(:any)。