如何通过href传递(“ /”)

时间:2018-07-13 08:35:56

标签: php codeigniter

我在链接中传递了一个包含/的ID,例如:171/CR/EOW1/14

它显示正确,但是在控制器功能中,它仅使用斜杠前的第一个字母。例如:171

我该如何解决这个问题?

enter image description here

5 个答案:

答案 0 :(得分:2)

  

您的问题令人难以置信。但出于此目的,我假设您要传递整个字符串171/CR/EOW1/14。不能将字符串的不同部分视为不同的参数。

您使用的是未转义的斜杠。因此,代码点火器的路由认为171之后的url部分是路由字符串中的更多参数。

如果您要传递网址,请使用urlencode(),然后使用urldecode()处理要传递的字符串中的斜杠。

或使用addslashes()

addslahes()

urlencode()

答案 1 :(得分:0)

您可以使用uri_segment,这应该会有所帮助。

http://example.com/index.php/controller/action/1stsegment/2ndsegment

它将返回

$this->uri->segment(1); // controller
$this->uri->segment(2); // action
$this->uri->segment(3); // 1stsegment
$this->uri->segment(4); // 2ndsegment

答案 2 :(得分:0)

在PHP 5.6中,您可以检索一个变量参数列表,该列表可以用...(扩展)运算符指定

function do_something($first, ...$all_the_others)
{
    var_dump($first);
    var_dump($all_the_others);
}

或者如果使用的是次要版本,则必须指定单独的参数变量

function do_something($first, $second, $third)
{
    var_dump($first);
    var_dump($second);
    var_dump($third);
}

编辑:

您可以将网址路由到该函数,例如

$route['products/(:any)'] = 'catalog/do_something';

请检查documentation以获得有关网址路由的更多详细信息

答案 3 :(得分:0)

在ignigner中将URI段传递给您的方法 visit codeIgniter docs

如果您的URI包含两个以上的段,它们将作为参数传递给您的方法。

例如,假设您有一个这样的URI:

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

您的方法将传递URI段3和4(“凉鞋”和“ 123”):

<?php
class Products extends CI_Controller {

        public function shoes($sandals, $id)
        {
                echo $sandals;
                echo $id;
        }
}

答案 4 :(得分:-1)

您可以使用如下问号:

?first=171&second=CR

有关更多信息,请参见http://html.net/tutorials/php/lesson10.php

相关问题