Php 获取控制器-Codeigniter的索引函数中的uri段

Php 获取控制器-Codeigniter的索引函数中的uri段,php,codeigniter,Php,Codeigniter,我有一个网址 www.xample.com/app/pay/11 工资是我的控制者。 控制器定义为 class Pay extends CI_Controller { function __construct() { parent::__construct(); $this->load->library('tank_auth'); $this->load->model('users'); }

我有一个网址

www.xample.com/app/pay/11

工资是我的控制者。 控制器定义为

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 ?
    }
}
我没有在这里使用任何附加函数。我使用的是索引函数。如何获取值11?

您可以使用该函数对发送到此类的任何内容运行
index()
函数

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()

您可以使用
index()
函数运行发送到此类的任何内容

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()

您可以使用codeigniter的URI段类。。 它就像
$this->uri->segment(n)

在你的情况下,你需要得到第三段

因此,它将是-

echo $this->uri->segment(3);

您可以使用codeigniter的URI段类。。 它就像
$this->uri->segment(n)

在你的情况下,你需要得到第三段

因此,它将是-

echo $this->uri->segment(3);

在config/autoload.php中启用url帮助程序

$autoload['helper'] = array('url');
或在所需控制器或其方法中加载url帮助程序

$this->load->helper('url');
然后在控制器中使用下面的命令

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

在config/autoload.php中启用url帮助程序

$autoload['helper'] = array('url');
或在所需控制器或其方法中加载url帮助程序

$this->load->helper('url');
然后在控制器中使用下面的命令

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

尝试使用此功能。


尝试使用此函数。

这会出现404错误,因为类中没有函数“11”。Codeigniter将“11”视为一个函数,请先加载url帮助器。我想对您进行更多描述,但现在需要离开,希望我的回答对您有所帮助。只要看一下codeigniter用户指南,你就可以得到关于codeigniter的所有信息。没有,我得到了。你没有得到我所要求的,我猜Helper类已经加载,但我仍然得到页面未找到错误。Pay是我的控制器这给出了一个404错误,因为没有函数“11”在类中.Codeigniter将“11”视为一个函数,首先加载url帮助程序。我想对您进行更多描述,但现在需要离开,希望我的回答能对您有所帮助。只要看一下codeigniter用户指南,你就可以得到关于codeigniter的所有信息。没有,我做到了。你没有得到我所要求的,我猜Helper类已加载,但我仍然得到页面未找到错误。Pay是我的控制器