CodeIgniter Forums

Full Version: Route Big Question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi. It is possible to make a route like this:
PHP Code:
$route['search/(:any)/(:any)/(:any)/?search=(:any)'] = 'servers/search/$1/$2/$3/?search=$4'// Search by Type / Game / Location / Keywords 


I have a script like GameTracker (if you know the website) and I would like to create a search with some features. But, also I would like to let visitors to query by words. My question: How can I make an URL which allows me to query even words ?
Example:

PHP Code:
http://localhost/search/nameorip/csgo/UK/?search=codeigniter.com 


Any idea ? I need to write .htaccess ?

P.S: I try to rewrite this script with Codeigniter. When was raw PHP I had this code:

PHP Code:
RewriteCond %{QUERY_STRING} ^matching=([^&]+)$ [NC]
RewriteRule   ^search/([a-z0-9_]+)/([A-Z_]+)/([a-z]+)/?$ servers.php?game=$1&location=$2&query_by=$3&matching=%[NC,L
I would highly recommend doing something more along the lines of 

Code:
http://localhost/search?nameorip=$var&csgo=$var&country=$var&query=$var


Otherwise, the standard .htaccess should work. Be sure to follow the routing rules found in the documentation. Order of routes is very important.
(05-10-2016, 11:21 AM)albertleao Wrote: [ -> ]I would highly recommend doing something more along the lines of 

Code:
http://localhost/search?nameorip=$var&csgo=$var&country=$var&query=$var


Otherwise, the standard .htaccess should work. Be sure to follow the routing rules found in the documentation. Order of routes is very important.

Ok, but my config is set to using default , i mean site like this domain.com/controller/method/etc/ and I can't use
it like that...
Yes, you can.
Use $this->input->get('nameorip') to fetch the parameters in the url.
EDITED :
I can't rewrite URL to something like that /$1/$2/$3?something=$4... I can write it until 3, then I can't. The problem is that $4 can be a string or a group of words ... Do you understand ?Smile
Use the URI Class:

PHP Code:
$uri $this->uri->segment(30); 
(05-11-2016, 10:13 AM)InsiteFX Wrote: [ -> ]Use the URI Class:

PHP Code:
$uri $this->uri->segment(30); 

I tried this, but I can't use it for more words...