How to customize Yii's default error pages?

Member

by daisha , in category: PHP Frameworks , 2 years ago

How to customize Yii's default error pages?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by domenico , a year ago

@daisha 

You can customize Yii's default error pages by following these steps:

  1. Create a new folder named "error" in your "views" folder.
  2. Inside the "error" folder, create a new file for each of the error codes you want to customize (for example, "404.php" for a 404 error).
  3. In each of these files, you can customize the HTML and CSS to your liking, and add any additional functionality you require.
  4. At the bottom of each file, you can add a link back to your homepage or other relevant pages.
  5. To ensure that Yii uses your custom error pages instead of the default ones, you need to modify your main configuration file (usually located at "protected/config/main.php").
  6. In the "components" section of the configuration file, add the following code:


'errorHandler'=>array( 'errorAction'=>'site/error' ),

  1. Save the configuration file, and your custom error pages should now be active.