Welcome Guest, Not a member yet? Register   Sign In
Customizable 404 Error Pages for Specific Routes
#7

(08-23-2024, 12:05 AM)kenjis Wrote: I still recommend the implementation like this:

PHP Code:
// Normal route
$routes->post(
    'api/v1/ticket-history/record-change',
    'TicketHistoryController::recordChange'
);
// For 405 error
$routes->match(
    ['GET''DELETE''PUT'],
    'api/v1/ticket-history/record-change',
    'Datamweb\BlankCI\Controllers\Errors::show405'
); 

This approach is definitely not suitable for me, as it requires defining individual error handling for each disallowed method separately. With an increasing number of routes, this method becomes overly complex and hard to maintain.

Code:
+--------+--------------------------------------------+
| Method | Route                                      |
+--------+--------------------------------------------+
| GET    | api/v1/ticket-history/record-change        |
| PUT    | api/v1/ticket-history/record-change        |
| DELETE | api/v1/ticket-history/record-change        |
| POST   | api/v1/ticket-history/record-change        |
+--------+--------------------------------------------+

Quote:or add a new method to generate such routes internally.
E.g.,
PHP Code:
$routes->method(
    ['POST'// Allowed methods
    'api/v1/ticket-history/record-change',
    'TicketHistoryController::recordChange',
    'Datamweb\BlankCI\Controllers\Errors::show405'// Controller for errors
); 

The second suggestion seems appealing and logical, but I currently have no idea on how to implement it.
Thank you for participating in this discussion!
Reply


Messages In This Thread
RE: Customizable 404 Error Pages for Specific Routes - by datamweb - 08-23-2024, 12:42 AM



Theme © iAndrew 2016 - Forum software by © MyBB