将多页URI函数映射到同一视图


Map multiplle URI functions to same view

在使用codeigniter时,我有一个用于退出页面的控制器。我希望用户能够访问网址site.com/example/copy、site.com/example/recredit,每次都加载相同的页面并传递不同的变量,如下所示:

class example extends Secure_Controller {
    public function revise()
    {
        $id = $_GET["id"];
        $show_for_edit("revise", $id);
    }
    public function copy()
    {
        $id = $_GET["id"];
        $show_for_edit("copy", $id);
    }
    public function show_for_edit($edit_type, $id)
    {
        //A lot of database queries that I don't
        //want duplicated under revise() and copy()
        $data["id"] = $id;
        $data["edit"] = $edit_type;
        $this->load->view('model', $data);
    }
}

但我收到一个错误:

致命错误:调用未定义的函数show_for_edit()

有什么想法吗?

在PHP中,当调用该方法的对象没有引用(即为null)时,就会发生此错误。

在您的情况下,调用方法"show_for_edit"的对象为null,因此出现了错误。

检查调用此方法的变量,确保它不是null,并且是"example"类的实例。

此外,我不确定这些调用$show_for_edit ("check", $id)$show_for_edit ("copy", $id)是否正确。我认为他们应该是:

$this-> show_for_edit ("check", $ id);

$this-> show_for_edit ("copy", $ id);