Welcome Guest, Not a member yet? Register   Sign In
Throwing a 404 with CI
#1

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

}
#2

[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();
#3

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

Oh, how could I have missed that?

Many thanks
#4

[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.




Theme © iAndrew 2016 - Forum software by © MyBB