CodeIgniter Forums
uri segment vs form GET uri into same controller...? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: uri segment vs form GET uri into same controller...? (/showthread.php?tid=13156)



uri segment vs form GET uri into same controller...? - El Forum - 11-12-2008

[eluser]steward[/eluser]
Say I am looking at page 3 of some result set.
So the next/prev page links are :

mysite.com/index.php/video/browse/page/2
mysite.com/index.php/video/browse/page/4

In the page navigation bar, I have a "jump to page" field.
Suppose the user types in 87 and clicks the jump button.

This will generate a GET request something like:

mysite.com/index.php/video/browse?page=87

But what I need now is

mysite.com/index.php/video/browse/page/87

I can invent solutions, but this must be a common/easy problem
(he says hopefully).

How does a controller distinguish between these two equivalent entry points?
Noob here. Which part of the manual do I need to re-read?


uri segment vs form GET uri into same controller...? - El Forum - 11-12-2008

[eluser]JoostV[/eluser]
You could do this:
1. Change your form action to post
2. Send it to a controller like video/go
3. Fetch the post value and redirect

This would be in controller video/go:
Code:
function go()
{
    // Fetch the page number from post
    // Typecast jump_to_page as an absolute integer first
    $page_id = abs((int) $this->validation->jump_to_page);
    
    // Redirect the user to the right page
    redirect('video/browse/page/' . $page_id, 'refresh');
}

Don't forget to set a validation rule for your jump_to_page field: trim|numeric

For a better user experience, you could calculate the number of pages and add a jQuery auto completion script to the jump_to_page field in video/browse. (or change the field to a dropdown with valid page numbers)


uri segment vs form GET uri into same controller...? - El Forum - 11-13-2008

[eluser]steward[/eluser]
Perfect thank you.

The input class is where I need to look.

POST works great in this case.
From the manual somewhere: "CI does not do GET".
I will have to wrap my head around that.