Setting 404 Status Code |
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() { 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 Code: ErrorException I thought I was following the manual, but maybe I am missing something. Any help/suggestions would be appreciated. Marc
In the closure the $response is not initialize, and there is not $this->response.
THANK YOU! I finally got a correct 404 response (it used to be 200 and my SEO guy was complaining about it)
Here is the code in app\Config\Routes.php (CodeIgniter version 4.4.1): $routes->set404Override(function () { $response = CodeIgniter\Config\Services::response(); $response->setStatusCode(404); return view('errors/html/error_404'); });
You can see things I made with codeigniter here: itart.pro its not overly impressive as I have very little time to learn.
(10-05-2023, 12:03 AM)Leo Wrote: THANK YOU! I finally got a correct 404 response (it used to be 200 and my SEO guy was complaining about it) Thanks for posting this!! Finally working correctly! |
Welcome Guest, Not a member yet? Register Sign In |