views:

283

answers:

2

I have this format on links:

blah/link/11

where blah is the controller and link is a function inside it. But now I want to send a number in the querystring. In normal non-MVC way I would have done like this:

page.php?id=11 

So what should I do for getting the eleven in my link function?

+3  A: 
class Blah extends Controller {

    function link( $id ) {
        // $id == 11
    }

}

reachable via URL blah/link/11

kemp
thanks, very simple but good.
marko
+1  A: 

There may be other ways to go about this, but it looks like CodeIgniter has a URI Class that will allow you to retrieve specific segments of your URI. So something like

$id = $this->uri->segment(3); //from a controller, I assume

should get you what you want.

It also looks like CodeIgniter will take additional URI parameters and pass them through as parameters to your action function.

#http://example.com/index.php/products/shoes/sandals/123
class Products extends Controller {

    function shoes($sandals, $id)
    {
        echo $sandals;
        echo $id;
    }
}
Alan Storm
I never realized he was working inside another framework. I thought he was building his own. :) I think the title was changed.
Chacha102