Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: autoRoute is not working, it is giving priority to manual routes. #9451

Closed
Anderson-Nascimento-Mendonca opened this issue Feb 14, 2025 · 9 comments

Comments

@Anderson-Nascimento-Mendonca

PHP Version

8.1

CodeIgniter4 Version

4.6.0

CodeIgniter4 Installation Method

Manual (zip or tar.gz)

Which operating systems have you tested for this bug?

Windows

Which server did you use?

apache

Database

No response

What happened?

I already have a working project, in version 4.5.8 with autoRoute true, and I went to update to 4.6.0 and the automatic route stopped, I noticed that it only worked in the manual route, I tried to modify it but without success.

Steps to Reproduce

Image

Expected Output

Image

Anything else?

It may be some new change that has happened, but I couldn't find it in the CHANGELOG.

@Anderson-Nascimento-Mendonca Anderson-Nascimento-Mendonca added the bug Verified issues on the current code behavior or pull requests that will fix them label Feb 14, 2025
@michalsn
Copy link
Member

Can you give us a clear example of what worked in v4.5.8 and stopped in v4.6.0?

What is the controller and method you're using to test this?

@michalsn michalsn added the waiting for info Issues or pull requests that need further clarification from the author label Feb 15, 2025
@Anderson-Nascimento-Mendonca
Copy link
Author

Image

like in this home controller, when I access the home it will redirect to the login controller, in version 4.6.0 I get a return saying that the login controller was not found, I use autorouter true, so it is automatic, and in this version it does not work unless I put a manual route in the routes.php file.

but in version 4.5.8 this way it works with an automatic route, without needing to put a manual route in the routes.php file

@michalsn
Copy link
Member

Sorry, but I cannot reproduce the problem.

Here are my steps - using the appstarter with v4.6.0 - of course, app\Config\Routing::autoRoute is enabled (but no other changes were made)

// app\Config\Routes.php (no changes here but I will include it to be clear)
<?php

use CodeIgniter\Router\RouteCollection;

/**
 * @var RouteCollection $routes
 */
$routes->get('/', 'Home::index');
// app\Controllers\Home.php
<?php

namespace App\Controllers;

class Home extends BaseController
{
    public function index()
    {
        return redirect()->to('/login');
    }
}
// app\Controllers\Login.php
<?php

namespace App\Controllers;

class Login extends BaseController
{
    public function getIndex()
    {
        var_dump('login::index');
    }
}

Entering the Home controller / gets me redirected to the /login without any problems.

Can you provide more details or context? Are the steps I provided accurate and does the same problem still occur on a new installation after following them?

@Anderson-Nascimento-Mendonca
Copy link
Author

Gravação de Tela 2025-02-16 103954.zip

Record a video of how I do it here, the same way I did in the video works in version 4.5.8

@michalsn
Copy link
Member

Sorry, but I won't download any files from "random" people on the Internet. If you can post it somewhere where I can view it online, I will.

Please follow the steps from my previous post and tell me if they are correct or if I should add something to reproduce the problem.

@Anderson-Nascimento-Mendonca
Copy link
Author

This is the same way you did it, the only difference when passing a var_dump I put an echo to display any message.
ok, I'll attach a link to play the video online.

https://streamable.com/13a6dp

@michalsn
Copy link
Member

Ok, seems like you missed the information that in v4.6.0 autoRoutesImproved is enabled by default: https://codeigniter.com/user_guide/installation/upgrade_460.html#config

To use auto-routes legacy, you have to set app\Config\Feature::$autoRoutesImproved to false.

@Anderson-Nascimento-Mendonca
Copy link
Author

Okay, thank you very much, I apologize, I really hadn't seen that change, as I mentioned in the topic if there was any update that I wasn't aware of, sorry.

@michalsn
Copy link
Member

No worries, I should have asked about it earlier.

@michalsn michalsn removed bug Verified issues on the current code behavior or pull requests that will fix them waiting for info Issues or pull requests that need further clarification from the author labels Feb 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants