Welcome Guest, Not a member yet? Register   Sign In
Autorouting Improved and Filters
#1

I just upgraded a site to version 4.3.7 from a 4.1.X version and as expected the auto routing changed.  I was able to change the methods etc. to use the HTTP verbs etc. without issue. However I had three or four filters based on URL values that don't appear to be working.  I have tried to break on the definition of the filter array in filters.php in the Config section and it doesn't hit the break.

Couple of questions:
Do specific routes in Config\routes.php override the auto routing?  In other words does it look at routes in Config\routes.php first if auto routing is turned on?
Can the auto routing improved and filters be used together?  When I try to use one of the URL's the before filter is supposed to redirect it comes back 404.?
Is it better to use defined routes using regular expressions etc. to redirect for login checks, old site URL's no longer valid etc. instead of filters?
I have tried to read all the documentation on the URI routing and filtering.
Thank you
Reply
#2

I would not recommend relying on autorouting. At least for this reason that you are faced with. It's unpredictable. 
Try to testing output data in filters - $_SERVER, route name, URI, etc... to understand what happened. Use dd() to suspend execution
Reply
#3

Quote:Important
For security reasons, if a controller is used in the defined routes, Auto Routing (Improved) does not route to the controller.
https://codeigniter4.github.io/CodeIgnit...g-improved
Reply
#4

(This post was last modified: 08-03-2023, 06:23 PM by kenjis.)

(08-03-2023, 09:52 AM)kbgkgould Wrote: Can the auto routing improved and filters be used together?

Yes, of course. If you configure correctly.
Reply
#5

I was able to get the filter working by specifying the filter alias and regular expression in the $routes->get call in Config\routes.php.

Also I went ahead and disabled the auto routing and added routes as needed.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB