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

NotFound on Router groups

Hi, I have a Router\Group that has a different domain, php $group->setHostName('sub.domain.localhost.com');

how can I create a different 404 page for this specific group ? php $router->notFound(...) will work only for the main domain.

Thank you.



1.4k
Accepted
answer

notFound() unavailable for Phalcon\Mvc\Router\Group.

You must create handler in notFound method where you can catch all 404 requests and call needful controller. Something like

$app->notFound( function () use ($app) {
         if($app->getHostName == 'sub.domain.localhost.com') {
            $my404 = new \App\Controllers\sub404Controller;
         }else{
            $my404 = new \App\Controllers\main404Controller;
         }
         return $my404;
    }
);