We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Intercept Exception DI

Hi,

$di->set(
    'db', 
    function () use ($config) {
        return Factory::load($config->database);
    }
);

How can i redirect to the page500 if the connexion to the database failed ?

Can i add redirection here or it's only on models ?



125.7k
Accepted
answer

Redirecting using Phalcon's methods might be tricky here. I'd just do a plain PHP redirect. Or at the very least you could echo a message then exit.