繁体   English   中英

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

[英]how to pass a (“/”) through href

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

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

我该如何解决这个问题?

在此处输入图片说明

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

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

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

或使用addslashes()

addslahes()

进行urlencode()

您可以使用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

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

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';

请检查文档以获取有关网址路由的更多详细信息

Codeigniter中将 URI段传递给您的方法 访问codeIgniter文档

如果您的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;
        }
}

您可以使用以下问号:

?first=171&second=CR

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM