PHP Project Unified Setup 404 page (including Yii framework)

Source: Internet
Author: User
Tags php template php tutorial yii
One, Apache + PHP to make custom 404 page method.

The first thing to do is to deal with files that don't really exist, by using Apache's . htaccess definition,

The method is to create a new. Htaccess, at the beginning of. Htaccess Plus: ErrorDocument 404/404.php (/404.php is a custom 404 page).

Second, under the YII framework set

When the requested page does not exist, Yii throws a Chttpexception exception, the exception code is 404, then how to handle this kind of exception in Yii, there are three ways:
1, do not do anything, Yii will deal with itself
When this class exception is thrown, Yii defaults to render the errorxxx.php (error404.php) template file under framework/view/
2, under Protected/views/system new errorxxx.php,yii will go to render the file
3. Configuring the exception handler
In configuration file main.php, add the following configuration, set the exception handling controller to Site/error

' ErrorHandler ' =>array (              //use ' site/error ' action to display errors              ' erroraction ' = ' site/error ',          ) ,  

Then add the error controller to the sitecontroller.php:
Public Function Actionerror ()      {          if ($error =yii::app ()->errorhandler->error)          {print_r ($error);              if (Yii::app ()->request->isajaxrequest)                  echo $error [' message '];              else                  $this->render (' Error ', $error);          }      }  

Finally, add the error.php template file under view/site/:
 
  Pagetitle=yii::app ()->name. '-Error ';  $this->breadcrumbs=array (      ' Error ',  );  ? >    

Error


The above describes the PHP Project Unified Settings 404 page (including the YII framework), including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.