Welcome Guest, Not a member yet? Register   Sign In
Codeigniter 4.2 Auto Routing weird thing happening
#1

(This post was last modified: 06-04-2022, 04:15 AM by seighth.)

In CI4.2 it says in the route file:

Code:
// The Auto Routing (Legacy) is very dangerous. It is easy to create vulnerable apps
// where controller filters or CSRF protection are bypassed.
// If you don't want to define all routes, please use the Auto Routing (Improved).
// Set `$autoRoutesImproved` to true in `app/Config/Feature.php` and set the following to true.
//$routes->setAutoRoute(false);


Is my understanding correct that the new feature requires developers to manually add a route for every single new static link/url? and that if the "Improved" auto routing is enabled that it would not require the developer to manually add every single static url?

Because I tried upgrading my website to CI4.2 and lo and behold every ajax request is not working, just 404 page not found... even when I enabled the "Improved" auto routing and the $routes->setAutoRoute(true) set to true... is that a bug?
Reply
#2

You can keep using the legacy autorouter and there should be no change. If you are having issues with your site after upgrade make sure you updated your spark and public/index.php files.
The new autorouting system is well documented, so definitely read the docs if you have not already. The gist of it is that you still don’t need to declare routes, but your controller methods must now include the name of the method: getUser(), postWidget(), getShowBlog()
Reply
Reply
#4
Exclamation 
(This post was last modified: 06-23-2022, 11:21 AM by Gary.)

Wow!

So much for simple "Download a new copy of the framework, and then replace the system folder" upgrades...

This change seems like a mammoth swallow!.... I'd go as far as disputing that "Improved" is appropriate in the heading: New Improved Auto Routing (https://codeigniter4.github.io/CodeIgnit...to-routing).

My site is also mostly Ajax-driven... this will mean I need to rename EVERY method... in the CI/PHP and JavaScript code throughout the whole site, and in 3rd Party apps that have been pulled into the site... if I want to use the auto-routing!!?

What happens to controllers that have previously handled more than one method (get/post etc)?

I've already had a mechanism built in for blocking certain inappropriate methods... so this seems like a double poke-in-the-eye... or wherever.

Is there not possibly a better way to implement functionality than using a prefix on user-defined function names?!  Maybe like a command/function that could be immediately called by the user in the function if they were wanting to invoke this functionality... like blockUnlessIsGet() or blockUnlessIsPost()?

And it's all very well just saying disable it... what happens when this option disappears and it becomes mandatory in v5 and there's an even bigger code-base balanced on this option (?)... many folk can already see how mandatory pans out.
Reply
#5

First, nothing has been decided yet on whether legacy auto routing will be discontinued.

Quote:Is there not possibly a better way to implement functionality than using a prefix on user-defined function names?!  Maybe like a command/function that could be immediately called by the user in the function if they were wanting to invoke this functionality... like blockUnlessIsGet() or blockUnlessIsPost()?

CodeIgniter is a community driven framework.

You could implement another routing subsystem and contribute it (sending a Pull Request).
Not all contributions will be adopted, but if they are supported by the community and follow the our rules of coding, they will be.
Reply
#6

(This post was last modified: 06-23-2022, 02:36 PM by Gary.)

Thanks for the feedback kenjis, also for the implicit vote of confidence in my coding-skills... truth be told, at best I'm a complete hack... it'll be a while yet before I'll be up to tackling a routing subsystem.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB