简体   繁体   English

从Codeigniter URL抓取参数数据

[英]Grabbing parameter data from Codeigniter URL

I am working on a CI project and have a need to send data to a controller as a url parameter. 我正在研究CI项目,需要将数据作为url参数发送到控制器。 I am used to doing something like this. 我习惯做这样的事情。

<a href="site/controller/function?id=1">

Then I am able to grab the parameter using $_GET. 然后,我可以使用$ _GET获取参数。

However I was told to use this method. 但是,我被告知要使用这种方法。

<a href="site/controller/function/1">

I did this and it shows up in the url when I click on the link, but I have no idea how to grab the actual parameter. 我做到了,当我单击链接时它显示在url中,但是我不知道如何获取实际参数。

Any advice? 有什么建议吗?

I figured it out, I used the following. 我想通了,我使用了以下内容。

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

And this got me the id number I passed. 这给了我我通过的身份证号码。

You better should use like below in your codeIgniter function. 您最好在您的codeIgniter函数中使用如下所示。 Even though your code also fine. 即使您的代码也可以。

function funcName ($param1)
{
 echo $param1;
}

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

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