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

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

问题描述

对不起,打扰,但我希望有人可以帮助我一个很平常的问题,我在CI。我可以通过URL使用CI的例子发送一个变量,例如:

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是否将允许我这样做。有人可以告诉我如何传递2个变量在CI和一个方法,可以检索他们我试过:

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

p>

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

以下是一个示例

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天全站免登陆