EllisLab text mark
Advanced Search
     
How to Convert Form Get Method (Query String) URI into Segment URI
Posted: 11 November 2012 04:22 PM
Joined: 2012-11-11
9 posts

Hi all,

I’ve been searching for a while on Google, but have only found how to enable Query Strings http://www.askaboutphp.com/58/codeigniter-mixing-segment-based-url-with-querystrings.html .

I have a form that uses a GET method and produces this URI,

books/course?course_id=CC100&format=XML&submit=Submit 

I want to convert this URI to use Segments, just as a POST method would produce.
The ideal URI I would like is:

books/course/CC100/XML 

Anyone know how I’d go about this?

 

 
Posted: 11 November 2012 08:50 PM   [ # 1 ]   [ Rating: 0 ]
Joined: 2012-11-01
81 posts

Any particular reason why you would want to do this?

I’m still fairly new to CI, but you could have two functions in your Books controller—one that hosts the form, and another that displays the results using a redirect. You could have your form controller display the form submitting it via post, format the output to a segmented URI, then redirect to a second controller that just shows the results.

 
Posted: 12 November 2012 03:17 AM   [ # 2 ]   [ Rating: 0 ]
Joined: 2012-11-11
9 posts

The reason why I must use a GET method is it’s part of the brief.

“Three main HTTP GET requests are required to be implemented. Each should be implemented as JSON and XML according to the URL of the request :-

A. Books by course

http://www.cems.uwe.ac.uk/~<yourusername>/atwd/books/course/<course-id>/xml
http://www.cems.uwe.ac.uk/~<yourusername>/atwd/books/course/<course-id>/json”

I’m using a post method for another form and it generates the correct URI structure, it’s just a problem I’m experiencing with a GET method.

 
Posted: 12 November 2012 03:33 AM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2007-11-28
2435 posts

In my knowledge, there’s two options: 1) change the action URL via Javascript 2) use an intermediary controller to process the GET request and redirect appropriately. Perhaps someone else has another solution that I’m unaware of.