How to Generate 404 error forcefully in Yii

16,943
throw new CHttpException(404,'The specified post cannot be found.');

http://www.yiiframework.com/doc/guide/1.1/en/topics.error

Share:
16,943
Arif
Author by

Arif

Updated on June 16, 2022

Comments

  • Arif
    Arif almost 2 years

    I am using Yii framework and i want to generate 404 error if no recode found in database. Is there any smart way so that Yii default error handler should be invoked.

    thanks in advance.

  • Highmastdon
    Highmastdon almost 11 years
    @imre-l Is it possible to return an Http Error without throwing an exception? Because I'm using MailLogRoute and now even simple 403 errors are mailed to me. It's an intentional error, so not a failure of a programmer so I think it shouldn't be an Exception. Is there a 'cleaner' way? > just return a http response with 403 without using CHttpException?
  • diego nunes
    diego nunes almost 11 years
    Have you tried using "200" as code? It's the "OK", so I think the server should let it pass.