Hi, In my project i have a Plugin (Error) where i capture all exception, and show a page 500..
class ErrorPlugin extends Plugin {
public function beforeException($event, $dispatcher, $exception) {
$this->view->setLayout('error');
$dispatcher->forward(array(
"controller" => "errors",
"action" => "show500",
"params" => array("code" => 500, "error" => $exception->getMessage() . '<br/>' . $exception->getTraceAsString())
));
return false;
}
}
But when i have a problem in my services.php like error on connect to db or connect to redis, this doesn't work..
How can i use "dispacher->forward" in my services.php?
Obs: I tried de code bellow, but dont have success.
$di->setShared('db', function ($try = false) use ($config) {
try {
return new \Phalcon\Db\Adapter\Pdo\Mysql(array(
"host" => $config->database->host,
"username" => $config->database->username,
"password" => $config->database->password,
"dbname" => $config->database->dbname,
'charset' => $config->database->charset,
//"dialectClass" => '\Phalcon\Db\Dialect\MysqlExtended'
));
} catch (Exception $e) {
$dispatcher = new \Phalcon\Mvc\Dispatcher();
$dispatcher->forward(array(
'controller' => 'errors',
'action' => 'show500',
'params' => array(
'code' => 500,
'error' => $e->getMessage()
)
));
}
});