Welcome Guest, Not a member yet? Register   Sign In
Query Strings
#1

[eluser]Spockz[/eluser]
You'll probably think. "O dear, yet another post about query strings." But I didn't find something that applies to this problem.

I'd like to make URLs that contain best of both worlds. 'Segments' and the query string. This is to accomplish the following:
Code:
http://somewhere.com/controller/function/?q=something nice&way=good

I've got this working partially. If I leave out the ? all goes well and the appropiate controller and function are loaded. However if it's left in CI generates a 404 error.

So I tried the following:
Code:
- Turning query strings on.
- Using rewrite rules to get rid of the ?
  - ([^/]*)\/\?([^/?]*)$ ./$1/$2
  - ^([^/]*)/\?(.*)$ ./$1/$2

Neither of these work, as $_SERVER['REQUEST_URI'] still contains the '?'. How would you get rid of the '?' in the URL, or what would do to prevent CI from showing the 404 instead of calling the right controller and function?

edit:
To clarify. The following works:
Code:
http://example.com/controller/function/q=a&r=b
The thing that doesn't work is when I try:
Code:
http://example.com/controller/function/?q=a&r=b

I think i'll need a Rewrite Rule that get's rid of the '?'. However, my attempts (as shown above, haven't succeeded.
#2

[eluser]GSV Sleeper Service[/eluser]
why not just pass them directly to your method?
Code:
class Your_controller extends Controller {

    function your_function($q = false,$r =false){
        ...
    }

}

you'd then be able to construct your example URLs like
Code:
http://example.com/controller/function/a/b
#3

[eluser]Spockz[/eluser]
I want to be able to add a lot of additional parameters. Your solution won't work then.


I found the solution: http://ellislab.com/forums/viewthread/72730/P10/#363542




Theme © iAndrew 2016 - Forum software by © MyBB