Welcome Guest, Not a member yet? Register   Sign In
Route Big Question
#1

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
Reply
#2

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.
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
Reply
#3

(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...
Reply
#4

Yes, you can.
Use $this->input->get('nameorip') to fetch the parameters in the url.
Reply
#5

(This post was last modified: 05-11-2016, 07:18 AM by gaska96.)

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
Reply
#6

Use the URI Class:

PHP Code:
$uri $this->uri->segment(30); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#7

(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...
Reply




Theme © iAndrew 2016 - Forum software by © MyBB