从URL获取值

时间:2016-02-17 20:11:54

标签: php codeigniter url

在此网址中:www.example.com/transaction/summary/10我可以通过以下方式获取10

$this->uri->segment(3);

但是,与其他一些GET参数一起,我怎样才能获得该值?

例如:www.example.com/transaction/summary?local_branch=1/10

PS:GET参数可能超过1。

3 个答案:

答案 0 :(得分:0)

要获得这些GET参数,您可以使用:

$this->input->get('some_variable', TRUE);

根据此处的SO link

example.com/?some_variable=hey

答案 1 :(得分:0)

如果您仍希望保留CI样式而不是添加细分:

<强> URL:

www.example.com/transaction/summary/10/1/TEST

<强>区隔:

$this->uri->segment(3); // 10
$this->uri->segment(4); // 1
$this->uri->segment(5); // TEST

或者,如果您想使用查询字符串,则可以在查询字符串中添加params并使用$_GET获取值:

www.example.com/transaction/summary/10/?local_branch=1&test=test

答案 2 :(得分:0)

好的,Codeigniter中的段是mysite.com/page/page-name之类的斜杠之间的内容。要获取页面名称值,我会得到第二个段,或$this->uri->segment(1)。要获取查询字符串($ _GET)传递的字符串,您只需使用示例中的$_GET['local_branch']或Codeigniter的情况,作为@Tom答案:$this->input->get('local_branch')

在这种情况下,您可以展开由 / 分隔的值。

$localBranch = $_GET['local_branch'];

// Or
$localBranch = $this->input->get('local_branch');

// And split using the / as delimiter if is need.
$localBranch = explode('/', $localBranch);

// Output
// Array(0 => 1, 1 => 10)

这样可以在同一查询字符串中传递许多值。

相关问题