Welcome Guest, Not a member yet? Register   Sign In
Setting 404 Status Code
#1

Recently discovered that my 404 override was throwing errors silently into the logs in production. Trying to troubleshoot it this morning. 

This is my code in the app/Config/Routes.php file:

PHP Code:
$routes->set404Override(static function() {
   $response->setStatusCode(404);
   echo view("error_404.php");
 }); 

This produces an error message in the log (in production) (Line 23 being the $response->setStatusCode(404) line):

Code:
CRITICAL - 2023-06-21 21:30:31 --> Undefined property: CodeIgniter\Router\RouteCollection::$response
in APPPATH/Config/Routes.php on line 23.
1 APPPATH/Config/Routes.php(23): CodeIgniter\Debug\Exceptions->errorHandler()
2 SYSTEMPATH/CodeIgniter.php(954): CodeIgniter\Router\RouteCollection->Config\{closure}()
3 SYSTEMPATH/CodeIgniter.php(387): CodeIgniter\CodeIgniter->display404errors()
4 FCPATH/index.php(67): CodeIgniter\CodeIgniter->run()
If I force it to try and load a bad page in development environment, it throws:

Code:
ErrorException
Undefined variable $response
APPPATH/Config/Routes.php at line 23

22    $routes->set404Override(static function() {
23        $response->setStatusCode(404);
24        echo view("error_404.php");
25    });

I thought I was following the manual, but maybe I am missing something. Any help/suggestions would be appreciated.
Marc
Reply


Messages In This Thread
Setting 404 Status Code - by SoccerGuy3 - 06-22-2023, 07:46 AM
RE: Setting 404 Status Code - by Mni.day - 06-22-2023, 02:36 PM
RE: Setting 404 Status Code - by kenjis - 06-22-2023, 02:53 PM
RE: Setting 404 Status Code - by Mni.day - 06-23-2023, 08:11 PM
RE: Setting 404 Status Code - by Leo - 10-05-2023, 12:03 AM
RE: Setting 404 Status Code - by SoccerGuy3 - 10-13-2023, 08:11 AM



Theme © iAndrew 2016 - Forum software by © MyBB