Welcome Guest, Not a member yet? Register   Sign In
uri segment vs form GET uri into same controller...?
#1

[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?
#2

[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)
#3

[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.




Theme © iAndrew 2016 - Forum software by © MyBB