Codeigniter从URL获得价值 [英] codeigniter get value from url

查看:66
本文介绍了Codeigniter从URL获得价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从codeigniter中的以下URL接收控制器中的值

How can i recieve the value in a controller from the following URL in codeigniter

http://localhost/directory/c_service/get_radius/lang=123

控制器:

class C_service extends CI_Controller {
function __construct()
{
parent::__construct();
}

public function get_radius()
{

i need to get the vLUE 123 here
like,
`$value=$get['lang'];`

}

谢谢

推荐答案

在Codeigniter中,您可以轻松完成

In Codeigniter you can simply do

public function get_radius($lang)
{
   var_dump($lang); //will output "lang=123"
}

因此您的链接可以简化为 http:// localhost / directory / c_service / get_radius / 123 如果您不想执行 explode('=',$ lang )获取值。

So your link could be simplified to http://localhost/directory/c_service/get_radius/123 if you don't want to do something like explode('=', $lang) to get your value.

不过,您还应该考虑添加默认值公共函数get_radius($ lang = 0)如果没有参数打开链接。

You should however also consider adding a default value public function get_radius($lang=0) if the link is opened without a parameter.

添加更多变量与公共函数get_radius( $ lang,$ other) for http:// localhost / directory / c_service / get_radius / 123 / other

Adding more variables is as easy as public function get_radius($lang, $other) for http://localhost/directory/c_service/get_radius/123/other

这篇关于Codeigniter从URL获得价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆