将多个URL函数映射到同一视图

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

 类示例扩展Secure_Controller {

公共函数修订()
{
$ id = $ _GET [“id”];
$ show_for_edit(“revise”,$ id);
}

公共函数copy()
{
$ id = $ _GET [“id”];
$ show_for_edit(“copy”,$ id);
}
\ n public function show_for_edit($ edit_type,$ id)
{
//很多数据库查询我不想在revise()和copy()下复制
$ data [“id” ] = $ id;
$ data [“edit”] = $ edit_type;
$ this-&gt; load-&gt; view('model',$ data);
}
}
</ code > </ pre>

但是我收到一个错误:</ p>


致命错误:调用未定义的函数show_for_edit()</ p>
</ blockquote>

有什么想法吗?</ p>
</ div>

展开原文

原文

In working with codeigniter, I have a controller for exiting a page. I'd like a user to be able to go to the url site.com/example/copy, site.com/example/revise, and the same page loads each time with a different variable passed, as so:

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);
    }
}

But I receive an error:

Fatal error: Call to undefined function show_for_edit()

Any ideas?

1个回答



在PHP中,当调用方法的对象没有引用时,会发生此错误,即它为null。</ p>

在您的情况下,调用方法“show_for_edit”的对象为空,因此出现错误。</ p>

检查调用此方法的变量并生成 确定它不是null并且是“example”类的一个实例。</ p>

此外,我不确定这些调用 $ show_for_edit(“check”,$ id)< / code>和 $ show_for_edit(“copy”,$ id)</ code>是正确的。 我认为它们应该是:</ p>

  $ this-&gt;  show_for_edit(“check”,$ id); 
</ code> </ pre>

和</ p>

  $ this-&gt;  show_for_edit(“copy”,$ id); 
</ code> </ pre>
</ div>

展开原文

原文

In PHP, this error occurs when the object that invokes the method does not have a reference, ie it is null.

In your case, the object that calls the method "show_for_edit" is null, and so it appears that mistake.

Check the variable that calls this method and make sure it is not null and is an instance of the "example" class.

Moreover, I am not sure that these calls $show_for_edit ("check", $id) and $show_for_edit ("copy", $id) are correct. I think they should be:

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

And

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

dsxgby126001
dsxgby126001 别客气。 看看php.net/manual/en/language.oop5.php。 官方PHP手册是一个很好的开始。
7 年多之前 回复
doubu2730
doubu2730 这正是我所缺少的,谢谢! 我想我现在应该稍微阅读一下OOPHP。
7 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问