CodeIgniter Forums
Throwing a 404 with CI - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Throwing a 404 with CI (/showthread.php?tid=31283)



Throwing a 404 with CI - El Forum - 06-13-2010

[eluser]iConTM[/eluser]
Can someone give an example of throwing a 404 with CI?

In the controller class I have something like this:

Code:
function article ($article_id)
{
  $article = $this->model->get_article($article_id);

  if (!$article)
  {
    //throw error 404
    return;
  }

}



Throwing a 404 with CI - El Forum - 06-13-2010

[eluser]Buso[/eluser]
Code:
if( ! $article) { show_404(); }

or you can use this cool style to replace the 'if' if you want:

Code:
$article OR show_404();



Throwing a 404 with CI - El Forum - 06-13-2010

[eluser]iConTM[/eluser]
[quote author="Buso" date="1276459149"]
Code:
if( ! $article) { show_404(); }

Oh, how could I have missed that?

Many thanks


Throwing a 404 with CI - El Forum - 06-13-2010

[eluser]pickupman[/eluser]
Unless you have created a custom 404 page, you may want to create a user friendly one. Or redirect to a page that you could offer some suggestions of other recent articles. Then they won't get the generic message page.