如何如何使用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);
如何通过PhalconPHP向用户显示500错误?我使用此代码显示404错误(显示error404.volt视图)和500错误(显示error500.volt视图)。 404错误页面按预期显示...
您可以通过在转发控制器的操作中设置请求的状态来执行此操作。在您的情况下indexController :: error500Action()
我在public / index.php