开发者

How does posting query parameters in CodeIgniter work?

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开发者_如何学Go 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?


class Blah extends Controller {

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

}

reachable via URL blah/link/11


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;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜