First deal with the situation where the file really does not exist. The method is to use Apache’s .htaccess definition. The
method is to create a new .htaccess and add: ErrorDocument 404 /404.php (/404. php is a custom 404 page).
2. Set up under the yii framework
When the requested page does not exist, yii will throw a CHttpException exception with the exception code 404. So how does yii handle this type of exception? There are three following Method:
1. Don’t do anything, yii will handle it by itself
When this type of exception is thrown, yii will render the errorxxx.php (error404.php) template file under framework/view/ by default
2. In protected Create a new errorxxx.php under /views/system, Yii will render the file
3. Configure the exception handler
Add the following configuration in the configuration file main.php, set the exception handling controller to site/error
'errorHandler'=>array( // use 'site/error' action to display errors 'errorAction'=>'site/error', ),
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); } }
<?php $this->pageTitle=Yii::app()->name . ' - Error'; $this->breadcrumbs=array( 'Error', ); ?> <h2>Error <?php echo $code; ?></h2> <div class="error"> <?php echo CHtml::encode($message); ?> </div>
The above introduces the unified setting of 404 pages for PHP projects (including under the Yii framework), including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.