在Kohana中,您可以触发404错误吗? [英] In Kohana, can you trigger a 404 error?

查看:78
本文介绍了在Kohana中,您可以触发404错误吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为articles的控制器,该控制器创建商品模型,该模型从数据库中获取相关数据.

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

如果调用的方法返回false,我想触发404错误.这就是我到目前为止所拥有的.

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

我刚刚添加了自己的自定义钩子,该钩子将用户重定向到由Kohana触发的实际404(/articles/page-not-found/),但是有一种方法可以调用其内部的404方法来使Kohana提供处理我的控制器并使用我的新钩子?

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 ?

推荐答案

这对我有用:

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

您使用的Kohana是哪个版本?

What version of Kohana are you using?

这篇关于在Kohana中,您可以触发404错误吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆