在控制器 - Codeigniter的索引函数中获取uri段 [英] Get uri segment in index function of controller - Codeigniter
本文介绍了在控制器 - Codeigniter的索引函数中获取uri段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个网址
www.xample.com/app/pay/11
www.xample.com/app/pay/11
是我的控制器。
控制器定义为
where pay is my controller. The controller is defined as
class Pay extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->library('tank_auth');
$this->load->model('users');
}
function index()
{
//How can I get 11 from uri ?
}
}
Im不使用任何附加函数here.Im使用如何获取值11?
Im not using any additional function here.Im using an index function.How could I get the value 11?
推荐答案
您可以使用 _remap()
运行
You could use _remap()
to run the index()
function for anything sent to this class.
class Pay extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->library('tank_auth');
$this->load->model('users');
}
function _remap($method, $params=array())
{
$methodToCall = method_exists($this, $method) ? $method : 'index';
return call_user_func_array(array($this, $methodToCall), $params);
}
function index($val)
{
echo $val;
}
}
现在,当您转到 www.xample.com/app/pay/11
, index()
将被调用。
Now, when you go to www.xample.com/app/pay/11
, index()
will be called.
这篇关于在控制器 - Codeigniter的索引函数中获取uri段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文