Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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.1k
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;
    }
);