Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php的codeIgniter中的_remap有什么用途_Php_Mysql_Codeigniter - Fatal编程技术网

使用php的codeIgniter中的_remap有什么用途

使用php的codeIgniter中的_remap有什么用途,php,mysql,codeigniter,Php,Mysql,Codeigniter,您好,朋友们,有谁能解释一下在使用PHP的codeIgniter中,\u remap函数的用法,并给出示例和详细说明,请…参见 重新映射函数调用 如果控制器包含一个名为_remap()的函数,则无论URI包含什么,它都将被调用。它覆盖了URI确定调用哪个函数的正常行为,允许您定义自己的函数路由规则 例如: 您的url是localhost/index.php/user/index,您不想为此调用index,然后您可以使用\u remap()映射新函数视图,而不是像这样映射索引 public fun

您好,朋友们,有谁能解释一下在使用PHP的codeIgniter中,\u remap函数的用法,并给出示例和详细说明,请…

参见

重新映射函数调用

如果控制器包含一个名为_remap()的函数,则无论URI包含什么,它都将被调用。它覆盖了URI确定调用哪个函数的正常行为,允许您定义自己的函数路由规则

例如: 您的url是
localhost/index.php/user/index
,您不想为此调用
index
,然后您可以使用
\u remap()
映射新函数
视图
,而不是像这样映射
索引

public function _remap($method)
{
    if ($method == 'index')
    {
        $this->view();
    }
    else
    {
        $this->default_method();
    }
}

重新映射函数调用

如果控制器包含一个名为_remap()的函数,则无论URI包含什么,它都将被调用。它覆盖了URI确定调用哪个函数的正常行为,允许您定义自己的函数路由规则

例如: 您的url是
localhost/index.php/user/index
,您不想为此调用
index
,然后您可以使用
\u remap()
映射新函数
视图
,而不是像这样映射
索引

public function _remap($method)
{
    if ($method == 'index')
    {
        $this->view();
    }
    else
    {
        $this->default_method();
    }
}

在这段简短的代码中,我们应该在url中传递索引,以显示我们响应的内容。但是函数本身内部有_remap()。我们应该传递索引,而不是索引。假设您有很多函数,您刚刚将其命名为公共函数codeig(){},在url中传递codeig是一件很遗憾的事,对吗?。因此,您将使用_重新映射,并将codeig设置为hello或任意(您想要的函数名),现在您可以将hello或您命名的内容传递到您的函数url

class Tuts extends CI_Controller{
    public function index($name = 'john',$age=18){
        echo "Your name is $name, you are $age years old";
    }

    public function _remap($method){
        if ($method === 'indexs') { //you should have to type indexs in uri instead of index
            $this->index();
        }else{
            $this->default_method();
        }
    }

在这段简短的代码中,我们应该在url中传递索引,以显示我们响应的内容。但是函数本身内部有_remap()。我们应该传递索引,而不是索引。假设您有很多函数,您刚刚将其命名为公共函数codeig(){},在url中传递codeig是一件很遗憾的事,对吗?。因此,您将使用_重新映射,并将codeig设置为hello或任意(您想要的函数名),现在您可以将hello或您命名的内容传递到您的函数url

class Tuts extends CI_Controller{
    public function index($name = 'john',$age=18){
        echo "Your name is $name, you are $age years old";
    }

    public function _remap($method){
        if ($method === 'indexs') { //you should have to type indexs in uri instead of index
            $this->index();
        }else{
            $this->default_method();
        }
    }

我已经看到了上面的链接。在那之后我也无法理解。请用简单的方式向我解释我已经看到了上面的链接。在那之后我也无法理解。请用简单的方式向我解释参考,看看它是否有帮助。阅读此参考,看看它是否有帮助。阅读此