Codeigniter - How to get url variable value inside contoller function?

后端 未结 2 1507
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-11 02:19

I have URL like this: http://localhost/sitename/some-post-title/code=24639204963309423

Now I have one findUser function in my controller file

2条回答
  •  花落未央
    2021-02-11 02:44

    If your URI contains more then two segments they will be passed to your function as parameters.

    For example, lets say you have a URI like this:

    example.com/index.php/products/shoes/sandals/123
    

    Your function will be passed URI segments 3 and 4 ("sandals" and "123"):

     
    

    If you are using GET to get parameters, you can do like this:

    $this->input->get('get_parameter_name'); 
    

    Typically there is a one-to-one relationship between a URL string and its corresponding controller class/method. The segments in a URI normally follow this pattern:

    example.com/class/function/id/
    

    More details for Controllers find here and for GET find here

提交回复
热议问题