Error.php 1.4 KB
<?php

/**
 * @name ErrorController
 * @desc 错误控制器, 在发生未捕获的异常时刻被调用
 * @see http://www.php.net/manual/en/yaf-dispatcher.catchexception.php
 * @author liuziyang
 */
use Action\RootAction;

class ErrorController extends RootAction
{
    public function init()
    {
        $this->getView()->setLayout('error');
        $this->_viewLink()->offsetSetFile(100, $this->_css('style.default', true));
    }

    public function errorAction($exception)
    {
        //YAF_ERR_NOTFOUND_VIEW
        switch ($exception->getCode()) {
            case 517:
            case 516:
            case 515:
                //404
                $this->redirect('/404.html');
                break;
            case 521:
            case 520:
            case 519:
            case 518:
            case 514:
            case 513:
            case 512:
                $this->getView()->assign("exception", $exception);
                break;
            //break;
            default:
                //自定义的异常
                $this->getView()->assign("exception", $exception);
        }
    }

    public function indexAction()
    {

    }

    public function notFoundAction()
    {
        header("Not Found");
    }

    public function alertAction()
    {
        $alertMessage = $this->_session('system_alert')->__get('alert_message');
        $this->_assign('alertMessage', $alertMessage);
    }
}