yii抛出错误页面CHttpException

时间:2023-03-09 07:46:52
yii抛出错误页面CHttpException
public void __construct(integer $status, string $message=NULL, integer $code=0)
$status integer HTTP状态码,如403,404,500等等。
$message string 错误信息
$code integer 错误代码
源码:
framework/base/CHttpException.php
)
{
    $this->statusCode=$status;
    parent::__construct($message,$code);
}

如:
public function actionTest()
    {
        if(isset($_GET['category']))
        {$category=(int)$_GET['category'];echo '1';}
        else
        {throw new CHttpException(400,'invalid request');}
    }
yii抛出错误页面CHttpException
还可以给错误页面重定向-------》config/main.php
            'errorHandler' => array(
                'enabled' => TRUE,
                'class'=>'CErrorHandler',
                'errorAction' => 'index/error',//这样报错时就会跳到index控制器下面的error页面。
            )