Welcome Guest, Not a member yet? Register   Sign In
set404Override inside Route Groups
#1

(This post was last modified: 05-14-2021, 08:02 AM by georgeynr.)

Today, I was exploring CI 4 and I got stuck while setting custom 404 error inside route group.

PHP Code:
$routes->group('admin', function ($routes) {
    $routes->add('page''Welcome::index');
    $routes->set404Override(function () {
        echo 'Not Found admin';
    });
});

$routes->group('user', function ($routes) {
    $routes->add('page''Welcome::index');
    $routes->set404Override(function () {
        echo 'Not Found user';
    });
}); 

When I hit /admin/123 url, I should get 'Not Found admin'. Instead what I am getting is 'Not found user'. Can someone please help me what I am doing wrong or is it a bug? How can I manage to get separate 404 errors based on Route Groups.
Reply
#2

(This post was last modified: 05-17-2021, 08:16 PM by iRedds.)

set404Override() method set global handler for application.
Reply
#3

(05-17-2021, 08:15 PM)iRedds Wrote: set404Override() method set global handler for application.
So can you please help me figure out how to set 404 error based on Route Groups?
Reply
#4

You can try adding the last route to each group
PHP Code:
$routes->add('(:any)', function() {
 return 
'Not Found ....';
}); 
Reply
#5

(05-18-2021, 03:11 AM)iRedds Wrote: You can try adding the last route to each group
PHP Code:
$routes->add('(:any)', function() {
 return 
'Not Found ....';
}); 

Thanks! That's what I thought earlier.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB