Site search with CodeIgniter? Site search with CodeIgniter? codeigniter codeigniter

Site search with CodeIgniter?


You could just use a url like /search/search_term/page_number.

Set your route like this:

$route['search/:any'] = "search/index";

And your controller like this:

function index(){    $search_term = $this->uri->rsegment(3);    $page = ( ! $this->uri->rsegment(4)) ? 1 : $this->uri->rsegment(4);    // some VALIDATION and then do your search}


Just to update this question. It is probably best to use the following function:

$uri = $this->uri->uri_to_assoc()

and the result will then put everything into an associative array like so:

[array](    'name' => 'joe'    'location'  => 'UK'    'gender'    => 'male')

Read more about the URI Class at CodeIgniter.com


Don't quite understand what you mean by "affecting the url structure". Do you mean you'd want pagination to occur without the URL changing at all?

The standard pagination class in CI would allow you to setup pagination so that the only change in the URL would be a number on the end

e.g if you had 5 results to a page your urls might be

http://www.example.com/searchresults

and then page 2 would be

http://www.example.com/searchresults/5

and page 3 would be

http://www.example.com/searchresults/10

and so on.

If you wanted to do it without any change to the URL then use ajax I guess.