简体   繁体   English

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

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

I am passing an id containing / eg: 171/CR/EOW1/14 in the link. 我在链接中传递的ID包含/例如: 171/CR/EOW1/14

It is showing correctly, but in the controller function it is taking only the first letters before the slash. 它显示正确,但是在控制器功能中,它仅使用斜杠前的第一个字母。 eg: 171 例如: 171

How do I solve this problem? 我该如何解决这个问题?

在此处输入图片说明

Your question is incredibly vague. 您的问题令人难以置信。 But for the purposes of this, I'll assume that you want to pass the whole string 171/CR/EOW1/14 . 但出于此目的,我假设您要传递整个字符串171/CR/EOW1/14 Not parts of the string as different params. 不能将字符串的不同部分视为不同的参数。

you are using an un-escaped slash. 您使用的是未转义的斜杠。 So codeigniters' routing thinks the parts of the url after the 171 are more parameters in the route string. 因此,代码点火器的路由认为171之后的url部分是路由字符串中的更多参数。

if you want to pass a url, use urlencode() and then urldecode() to handle the slashes in the string you want to pass. 如果要传递url,请使用urlencode() ,然后使用urldecode()处理要传递的字符串中的斜杠。

Or use addslashes() . 或使用addslashes()

addslahes() addslahes()

urlencode() 进行urlencode()

You can use uri_segment , which should help. 您可以使用uri_segment ,这应该有所帮助。

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

it will return 它将返回

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

In PHP 5.6 you can retrieve as a variable argument list which can be specified with the ... (spread) operator 在PHP 5.6中,您可以检索变量参数列表,可以使用... (spread)运算符指定该列表...

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

or if you are using a lesser version you have to specify separate arguments variables 或者,如果您使用的是次要版本,则必须指定单独的参数变量

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

EDIT: 编辑:

You can route the url to this function like 您可以将网址路由到该函数,例如

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

Please check the documentation for more details about url routing 请检查文档以获取有关网址路由的更多详细信息

Passing URI Segments to your methods in codeigniter visit codeIgniter docs Codeigniter中将 URI段传递给您的方法 访问codeIgniter文档

If your URI contains more than two segments they will be passed to your method as parameters. 如果您的URI包含两个以上的段,它们将作为参数传递给您的方法。

For example, let's say you have a URI like this: 例如,假设您有一个这样的URI:

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

Your method will be passed URI segments 3 and 4 (“sandals” and “123”): 您的方法将传递URI段3和4(“凉鞋”和“ 123”):

<?php
class Products extends CI_Controller {

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

You can you use a question mark like: 您可以使用以下问号:

?first=171&second=CR

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

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

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