send 404 from controller

Permalink
Is there a method that can be called to show the 404 page from within a controller?

Would be really cool to be able to do
return $this->send404();


I am now using which seems to do what I want.
header('x', true, 404);
$this->render('/page_not_found');

ChristiaanB
 
JohntheFish replied on at Permalink Reply
JohntheFish
Controllers inherit a redirect method (which does not return).

$this->redirect('/path/to/another/page/');
ChristiaanB replied on at Permalink Reply
ChristiaanB
If you use that it sends a 301 status code and not the desired 404 on the requested url.
$this->redirect('/page_not_found');

So it will only tell that the page to which was being redirected is not found on the server not that the original url couldn't be found.
JohntheFish replied on at Permalink Reply
JohntheFish
I see what you mean.

I don't think any actual output is generated until you get to the view, so you may be able to bypass any C5 output and do something like:

print 'whatever error & redirect header you want';
exit;


I have never tried it, but its akin to how an ajax tool would return clean output, so maybe it would work.

I suspect that when Oregon wakes up there will be someone who has a much better and cleaner idea.