Search a site using CodeIgniter?

I need to do a simple pagination on a site; can someone tell me how to do this without affecting the structure of the url? I am currently using the default CodeIgniter URL structure, and I removed index.php from it. Any suggestions?

+1
source share
4 answers

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

Define your route as follows:

 $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 } 
+3
source

Just 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 in an associative array as follows:

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

Read more about the URI class at CodeIgniter.com

+1
source

I don’t quite understand what you mean by the structure of the URL. Do you mean that you want pagination to happen without changing the URL at all?

The standard pagination class in CI allows you to configure pagination so that the only change to the URL is the number at the end

For example, if you had 5 results per page, your URL might be

http://www.example.com/searchresults

and then page 2 will be

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

and page 3 will be

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

etc.

If you want to do this without any changes to the url then use ajax, I think.

0
source

Igniter code disables GET requests by default, but you can create an alternative if you want the URL to display a search bar.

Your url can be in the designation www.yoursite.com/index.php/class/function/request1:value1/request2:value2

 $request = getRequests(); echo $request['request1']; echo $request['request2']; function getRequests() { //get the default object $CI =& get_instance(); //declare an array of request and add add basic page info $requestArray = array(); $requests = $CI->uri->segment_array(); foreach ($requests as $request) { $pos = strrpos($request, ':'); if($pos >0) { list($key,$value)=explode(':', $request); if(!empty($value) || $value='') $requestArray[$key]=$value; } } return $requestArray ; } 

source: http://codeigniter.com/wiki/alternative_to_GET/

0
source

Source: https://habr.com/ru/post/1390453/


All Articles