如果不存在,则显示404错误

时间:2014-06-10 14:50:43

标签: php codeigniter http-status-code-404

我在CodeIgniter中遇到404错误问题。我在控制器中有错误:

public function show($id = 0)
{
    $review = $this->site_reviews->get_review($id);


    if ($review)
    {
              .....
    }
    else
    {
        show_404();
    }

现在,如果我添加到链接的末尾,例如:/?id = 13865或/?id = 42788?id = 42788一切顺利......如何show_404()..存在解决方案?

1 个答案:

答案 0 :(得分:0)

这种情况,当您的ID为codigniter格式时:

<强> $ ID = $这 - &GT; URI-&GT;链段(3)// URL:www.example.com/13865

当你使用核心php概念时,这种情况是get:

<强> $ ID = $ _ GET [&#39; ID&#39;] // URL:www.example.com ID = 13865

public function show($id = 0)
{
    $review = $this->site_reviews->get_review($id);


    if ($review)
    {
              .....
    }
    else
    {
        show_404();
    }