【问题标题】:what is the use of _remap in codeIgniter using php使用php的codeIgniter中_remap的用途是什么
【发布时间】:2013-11-22 06:27:36
【问题描述】:

你好,frnds 谁能解释一下使用 PHP 的 codeIgniter 中 _remap 函数的用途,并附上示例和描述清楚...

【问题讨论】:

标签: php mysql codeigniter


【解决方案1】:

here

重新映射函数调用

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

例如: 你的网址是localhost/index.php/user/index,而你不想为此调用index,那么你可以使用_remap()来映射新函数view,而不是像这样的index

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

【讨论】:

  • 我已经看到了上面的链接。之后我也无法理解。请用简单的方式解释我
【解决方案2】:

在这个简短的代码中,我们必须在 url 中传递 index 以显示我们回显的内容。但是在函数本身内部有 _remap() 。我们应该传递索引而不是索引。假设您有很多函数,而您只是将其命名为 public function codeig(){},在 url 中传递 codeig 是一种耻辱,对吧?因此,您将使用 _remap 并将 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();
        }
    }

【讨论】:

    猜你喜欢
    • 2023-03-22
    • 2018-02-23
    • 2011-05-21
    • 2010-11-05
    • 2012-03-09
    • 1970-01-01
    • 2018-05-10
    • 2021-03-27
    相关资源
    最近更新 更多