Using a query string inside of a clean url.

I've seen a couple posts on the forum however I don't know if that's exactly the answer I'm looking for. I just need to know if this is possible:


The only reason I need this is for the search functionality of my app. It seems to make more sense to put the search variables in a query string rather than cram them in to a uri segment. Is CI designed to do this natively? Again, I'm sorry for posting this again but the other posts didn't seem clear enough on this issue.

[eluser]Colin Williams[/eluser]
It's easily possible. Make sure these settings are in place:

$config['enable_query_strings'] = TRUE;
$config['uri_protocol'] = 'PATH_INFO'; // Anything but AUTO or QUERY_STRING


[eluser]Phil Sturgeon[/eluser]
Yup was pretty happy when I spotted this fix, until recently I always had to send search forms as a post variable to a redirect method, just to get the parameter into a CI friendly URL. Overkill!

Alternatively ou could rely on javascript.

attach an onClick() event to the submit button (or any field in the form with onChange() or onDirty() ) which urlencodes the search criteria before the submit.
In CI, you then take the param1 and urlunencode it which gives you all the information you need.

This is a much better way of sending Ajax search criteria as you do not have to worry about the number of key value pairs client side and can hand off the complicated stuff to a controller (e.g. embed within the search parameter the kind of search being done and then simply call a different controller or model from your generic search controller)

You also don't have to allow GET posts, which break one of the real design niceties of CI URLs


[eluser]Colin Williams[/eluser]
I only do this when I need to interface with some outside service that uses query strings. Otherwise, using the uri_to_assoc() method usually works well in place of a query string

I've done this for a simple text input search form.

I get this result;

But how do I get phrase back into CI?


[eluser]Colin Williams[/eluser]
do http://ci.localhost/books/search/phrase/my+search instead

Quote:do http://ci.localhost/books/search/phrase/my+search instead

Whilst that's fine for a small form, but the form I'm building it for has many variables.

So it'd be something like this;

That means I'd have to know which of the URI parameters to grab.

Also it still doesn't stop the + appearing in the my+search

I'm quite happy to use:

Until there is a clear cut way of doing this.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.