Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

sorry to bother but I was hoping someone could help me out with a quite mundane issue that I am having within CI. I am able to send a variable via the URL using CI's examples eg:

http://localhost/project/main/getproduct/24

within the getproduct() method of my main controller I can get the variable sent 24, without an issue.

however I now want to pass two variables via the URL, but I have no idea how to do this or whether CodeIgniter will allow me to do this. could someone please show me how to pass 2 variables in CI and a method that can retrieve them I have tried:

http://localhost/project/main/getproduct/24/45

and then within my getproduct method:

public function getproduct($productID, $factoryID){
  .....
}

but I'm finding my method can get the first variable without an issue but not the second variable. Could anyone point me in the right direction please. Many thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
382 views
Welcome To Ask or Share your Answers For Others

1 Answer

The accepted answer will work for this particular issue, but will not work if the url ever changes. To access multiple variables in your controller, simply add to the function definition.

http://localhost/project/main/getproduct/24/45

class Main extends CI_Controller {

    public function getproduct($productID = 0, $factoryID = 0)
    {
      // ProductID will be 25
      // Factory ID will be 45
    }
}

Reference: CodeIgniter User Guide


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...