Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Kohana, can you trigger a 404 error?

I have a controller called articles, which creates the articles model which gets the relevant data from the database.

I want to, if the method I call returns false, to trigger a 404 error. This is what I have so far.

 $articleName =  $this->uri->segment('articles');

 $article = new Articles_Model();

 $data = $article->getArticleUsingSlug($articleName);

 if (!$data) {
    Kohana::show_404; // This doesn't work.
 }

I just added my own custom hook which redirects the user to an actual 404 (/articles/page-not-found/) as triggered by Kohana, but is there a way I can invoke its internal 404 method to make Kohana give up processing my controller and use my new hook ?

like image 752
alex Avatar asked May 05 '09 23:05

alex


3 Answers

This works for me:

Event::run('system.404');

What version of Kohana are you using?

like image 172
pifantastic Avatar answered Sep 28 '22 09:09

pifantastic


Kohana / General / Error-handling / Kohana_404_Exception

/**
 * @param  string  URL of page
 * @param  string  custom error template
 */
throw new Kohana_404_Exception([string $page [, string $template]]);
like image 31
Sampson Avatar answered Sep 28 '22 09:09

Sampson


Kohana Docs tells you way to do it:

throw HTTP_Exception::factory(404, 'File not found!');
like image 35
Norman Edance Avatar answered Sep 28 '22 11:09

Norman Edance