使用 codeigniter 在 URL 中传递多个变量 [英] Passing multiple variables in URL using codeigniter

查看:16
本文介绍了使用 codeigniter 在 URL 中传递多个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉打扰,但我希望有人能帮助我解决我在 CI 中遇到的一个非常平凡的问题.我可以使用 CI 的示例通过 URL 发送变量,例如:

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

在我的主控制器的 getproduct() 方法中,我可以将变量发送 24,没有问题.

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

但是我现在想通过 URL 传递两个变量,但我不知道如何执行此操作或 CodeIgniter 是否允许我执行此操作.有人可以告诉我如何在 CI 中传递 2 个变量以及一种可以检索它们的方法吗?我试过:

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

然后在我的 getproduct 方法中:

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.

推荐答案

您可以使用 uri 来检索您的 url 中的值

You can use uri to retrieve values in your url

这是一个例子

public function getproduct()
{
  $productID =  $this->uri->segment(3);
  $factoryID =  $this->uri->segment(4);
  // ProductID will be 25
  // Factory ID will be 45
}

然后你可以随意使用这些值

Then you can just use the values as you please

这篇关于使用 codeigniter 在 URL 中传递多个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆