문제

컨트롤러가 호출되었습니다 articles, 데이터베이스에서 관련 데이터를 얻는 기사 모델을 만듭니다.

내가 호출하는 방법이 반환된다면 false, 404 오류를 트리거하려면. 이것이 내가 지금까지 가지고있는 것입니다.

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

 $article = new Articles_Model();

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

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

방금 Kohana에 의해 트리거 된대로 사용자를 실제 404 (/article/page-not-found/)로 리디렉션하는 나만의 사용자 정의 후크를 추가했지만 Kohana가 내 내부 404 방법을 호출하여 Kohana가 내 처리를 포기하는 방법이 있습니다. 컨트롤러 및 내 새 후크를 사용 하시겠습니까?

도움이 되었습니까?

해결책

이것은 나를 위해 작동합니다 :

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

Kohana의 어떤 버전을 사용하고 있습니까?

다른 팁

Kohana / 일반 / 오류 처리 / Kohana_404_Exception

/**
 * @param  string  URL of page
 * @param  string  custom error template
 */
throw new Kohana_404_Exception([string $page [, string $template]]);

코 하나 문서 당신에게 할 수있는 방법을 알려줍니다.

throw HTTP_Exception::factory(404, 'File not found!');
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top