2014-10-03 68 views
0

如何向用户显示500与PhalconPHP错误?PhalconPHP - 如何向用户显示500错误

我使用该代码来显示404错误(显示error404.volt视图)和500错误(显示error500.volt视图)。
按预期显示404错误页面,但不显示500错误页面。

$di->set('dispatcher', function() { 
    //Create/Get an EventManager 
    $eventsManager = new \Phalcon\Events\Manager(); 
    //Attach a listener 
    $eventsManager->attach("dispatch:beforeException", function($event, $dispatcher, $exception) { 
     //Handle 404 exceptions 
     if ($exception instanceof \Phalcon\Mvc\Dispatcher\Exception) { 
      $dispatcher->forward(array(
        'controller' => 'index', 
        'action' => 'error404' 
      )); 
      return false; 
     } 
     //Handle other exceptions 
     $dispatcher->forward(array(
       'controller' => 'index', 
       'action' => 'error500' 
     )); 
     return false; 
    }); 
    $dispatcher = new \Phalcon\Mvc\Dispatcher(); 
    //Bind the EventsManager to the dispatcher 
    $dispatcher->setEventsManager($eventsManager); 
    return $dispatcher; 
}, true); 

回答

1

您可以通过在转发控制器的操作中设置请求的状态来做到这一点。在你的情况indexController :: error500Action()

$this->response->setStatusCode(500, "Internal Server Error"); 
+0

我做了,它仍然不显示在浏览器中的错误。 – 2014-10-03 16:19:50

+0

然后尝试使用php函数标题(“HTTP/1.0 500内部服务器错误”); – Synaptickz 2014-10-03 21:53:03

+0

请参阅我的更新问题,当内部服务器错误发生时,使用功能标题当前在浏览器中不显示任何内容,我想向用户显示视图“error500”。 – 2014-10-03 22:02:38

相关问题