Reputation: 35
I'm currently working on a CodeIgniter application but I need the search functionality to be more readable, for both humans and CodeIgniter.
Here's what I currently get as the URL when submitting the form.
http://mydomain.com/search/?query=batman
And here's what I'm looking to end up with.
http://mydomain.com/search/batman
I'm not great with mod rewrites, but I imagine that's the route I'll need to take?
Thanks for any help.
Upvotes: 2
Views: 127
Reputation: 15609
Not a very nice method but:
What if you make it a POST
and put the variable into a separate controller. eg search($s)
public function search($s){
header('Location:http://yoursite.com/whatever/search/'. $s);
}
This should give you the result you need.
Upvotes: 0
Reputation: 5387
You can capture the onsubmit() event with javascript and then redirect to the url you want..
$('#myform').on('submit', function(e){
e.preventDefault();
var value = $('#input').val()
window.location = 'http://mydomain.com/search/' + value;
})
Of course, your controller will have to look like this:
class Search extends CI_Controller
{
public function index($term)
{
// code code
}
}
Upvotes: 0
Reputation: 7475
First change the form method
to POST
and in your search function you can then do something like this:
function search(){
if( $this->input->post(null) ){
$keyword = $this->input->post('keyword');
#do you processing with the post
}else{
$keyword = $this->uri->segment(3);
}
#for pagination
$config['base_url'] = base_url()."controller/search/".$keyword."/page/";
$config['uri_segment'] = 5;
}
Upvotes: 0
Reputation: 7108
You should use mod_rewrite, creating a script .htaccess in your script path:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)$ /index.php?query=$1 [L]
</IfModule>
Take a look to mod_rewrite docs for more infos http://httpd.apache.org/docs/current/mod/mod_rewrite.html
Upvotes: 1