Попробуйте следующие коды:
HTML:
<?=form_open(base_url(), array('id' => 'search'))?>
<input type="text" class="form-control" placeholder="Keyword..." name="query" id="search_query">
<button class="btn btn-default" id="btn-search" type="button">
Search
</button>
<?=form_close()?>
Javascript:
$("#btn-search").click(function(){
var query = $("#search_query").val();
window.location = '/search/'+query;
});
$('form#search').bind("keypress", function(e) {
if (e.keyCode == 13) {
e.preventDefault();
var query = $("#search_query").val();
return window.location = '/search/'+query;
}
});
Маршрут:
$route['search/(:any)'] = 'Controller/search/$1';
Контроллер:
public function search($keyword = null)
{
if($keyword == null)
redirect(base_url());
else
{
$keyword = urldecode($keyword);
$data = array(
'category' => $this->Category_Model->search($keyword)
);
$this->load->view('search', $data);
}
}