【问题标题】:fetching parameter in a link php codeigniter在链接php codeigniter中获取参数
【发布时间】:2017-07-06 14:14:06
【问题描述】:

说我有这个网址

http://localhost/newtkt/index.php/welcome/gettkt/PfIfiETYXzUpYRJf6RPvyncN4PgdN3

还有一个控制器功能

public function gettkt()
{
  //mydata
}

如何检索 url 附带的参数 PfIfiETYXzUpYRJf6RPvyncN4PgdN3 并使其成为我的控制器函数 gettkt() 中的变量,以便我可以在函数中使用参数,如 gettkt(thisparameter)。我希望我以最好的方式组织了我的问题。谢谢。

【问题讨论】:

  • 尝试 $this->request->param 或使用 $this->input->get()$this->uri->segment('3'); 其中 3 代表第三个参数
  • 我收到错误Undefined property: Welcome::$request
  • 使用$this->input->get()$this->uri->segment('3'); 其中33rd 参数
  • 是的,它现在与$this->uri->segment('3');合作
  • 非常感谢@urfusion

标签: php ajax codeigniter get


【解决方案1】:

你可以做两件事

方法01

public function gettkt($parm)
{
    echo $parm; # Prints PfIfiETYXzUpYRJf6RPvyncN4PgdN3
}

方法02

在 CodeIgniter 中使用 URI Class

$parm = $this->uri->segment(n); # Number point your parameter 
$parm = $this->uri->segment(3); # Prints PfIfiETYXzUpYRJf6RPvyncN4PgdN3

【讨论】:

    【解决方案2】:

    你可以使用

    $this->uri->segment('3'); //where 3 is for 3rd param
    

    欲了解更多信息,请访问URI

    【讨论】:

      猜你喜欢
      • 2017-12-17
      • 2017-04-30
      • 2014-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-09
      • 1970-01-01
      相关资源
      最近更新 更多