Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8358673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:52:31+00:00 2026-06-09T10:52:31+00:00

I want to display 404 error page for that i have made error404.php file

  • 0

I want to display 404 error page for that i have made error404.php file in my protected/view/system folder.

By default i have Sitecontroller and it contained error action function as below

public function actionError()
{
    if($error=Yii::app()->errorHandler->error)
    {

        if(Yii::app()->request->isAjaxRequest)
            echo $error['message'];
        else
            $this->render('error', $error);
    }
}

inside main config file it is defined as

    'errorHandler'=>array(
        // use 'site/error' action to display errors
        'errorAction'=>'site/error',
    ),

my problem is i need to customize 404 page only, rest of the error i need to handle the way it is being handle by sitecontroller’s error function. But i could not find a way to do that. If suppose i remove ‘errorAction’=>’site/error’, from the config main then it does show the 404 error by calling

        throw new CHttpException(404, 'Page not found');

but doing that i can only see the page without layout also other custom errors are treated same as 404 while they are not. I read the manual many times but i still cant able to resolve it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T10:52:33+00:00Added an answer on June 9, 2026 at 10:52 am

    Use this code for actionError:

    $app = Yii::app();
    if( $error = $app->errorHandler->error->code )
    {
        if( $app->request->isAjaxRequest )
            echo $error['message'];
        else
            $this->render( 'error' . ( $this->getViewFile( 'error' . $error ) ? $error : '' ), $error );
    }
    

    In views/site create error404.php for 404 errors and error.php for the rest.

    Or you can define param in the config for errors you like to handle differently and check error code against it:

    $app = Yii::app();
    if( $error = $app->errorHandler->error->code )
    {
        if( Yii::app()->request->isAjaxRequest )
            echo $error['message'];
        else    
            $this->render( 'error' . ( in_array( $error, $app->params[ 'customErrorPages' ] ) ? $error : '' ), $error );
    }
    

    Error handler works like this: when httpexception arise, component will check if there is any value in errorAction property and if there is any, will run this controller’s action. If there is no set value to the errorAction property, will display error view from system folder. So there is no need to mix error views from system view folder and controller’s view folder.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to display a 404 Error if a user reaches a page that
I want to display home page in case file missinng instead of file not
In Drupal 6, I would like to have certain Content Types display Error 404,
I have a simple quiz application and I want display a nice timer /
I have db with this table (TableToDo): http://goo.gl/NlTEk I want display all records in
I have a page that refuses to render in IE6. When I load the
In my website, website.com/downloads actually goes to website.com/index.php?page=downloads (with apache rewriting). I have a
I want to handle failed requests (for example, with http 404 error code in
The CodeIgniter has a very simple default error 404 message: 404 Page Not Found
I want redirect to error page when exception occured. If the code is not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.