Routes 4.0.0-beta.2 |
Hy all .
I have some user defined routes stored in database to do some redirects . example user/register (database stored) redirect to register (app defined route ) My thoughts of the day were to inject into Config\Routes or Events::on('pre_system' PHP Code: $routes->setAutoRoute(false); but seems that Config\Routes is called twice and throw error when adding the redirect How to inject new routes redirection and where ? Before declaring route ? after ?
There’s probably a better way to do it, but off the top of my head you could create as your last rule a catch-all that maps to a closure that checks your database for a match.
Personally - I'd create a controller who's only job was to check the database and handle those redirects. Put a catch-all route as the last one in the file that points to that controller. Or use that controller as your 404Override controller, where you could check those routes first, and redirect if found, or show your custom error page.
I solved it this way:
1) I created a table where I store the routes. 2) I created the "RouteModel" model 3) I created the Config\[environment]\Routes.php file with this content Code: <?php namespace Config; It will not be the optimal and clean solution, but it has solved my problem. I hope it can help you in some way ... Codeigniter 4 - Docker Image [github] [docker hub]
|
Welcome Guest, Not a member yet? Register Sign In |