Welcome Guest, Not a member yet? Register   Sign In
Auto Routing and redirect() not working
#5

(This post was last modified: 01-30-2023, 12:54 AM by objecttothis.)

(12-10-2022, 05:58 PM)kenjis Wrote: Auto Routing (Legacy) should work with your first config.
I don't know why it does not work.

Auto Routing (Improved) is much complex than  Legacy for the security reasons.
Read this carefully:
https://codeigniter4.github.io/CodeIgnit...to-routing

See below.  The issue is now redirect().

After returning from vacation I upgraded the core framework to 4.3.1 then walked through all the upgrade path steps. Still no dice, so to troubleshoot I commented out all my defined routes except for the root directory $routes->get('/', 'Login::getIndex');.  Then I ran php spark routes again and the  autorouting began working. So, I figured that it was one of my defined routes breaking auto routing of all controllers. I uncommented each defined route individually down to uncommenting all of them but autorouting remained working. Oh well.

After all that I'm still getting "The route for "testRoute" cannot be found." I can't seem to attach images, so I'll have to write this all in text.

In Routes.php I have:
PHP Code:
$routes->get('/''Login::getIndex'); 

That is routing properly. At the end of the getIndex function in the Login controller I have:
PHP Code:
return redirect('testRoute'); 

Under app\Controllers\ I have TestRoute.php
PHP Code:
<?php

namespace App\Controllers;
class 
TestRoute extends BaseController
{
 public function 
getIndex()
 {
 echo 
"hello world";
 }


When I navigate the browser to /public/ it loads getIndex() from Login.php but when it gets to the last line it kicks out:
PHP Code:
The route for "testRoute" cannot be found

It doesn't seem to matter what I change the controller to in the redirect() function.

php spark routes clearly shows:
PHP Code:
GET(auto)    testRoute                                          |      | \App\Controllers\TestRoute::getIndex                  honeypot csrf invalidchars honeypot secureheaders toolbar 

It's unclear to me why redirect isn't working. Can redirect() no longer be used with auto routing like it could be in CI3? If I navigate to /public/testRoute/ it displays "hello world" as it should.
Reply


Messages In This Thread
RE: Auto Routing (Legacy) not working - by kenjis - 12-10-2022, 05:58 PM
Redirect() not working - by objecttothis - 01-30-2023, 12:44 AM



Theme © iAndrew 2016 - Forum software by © MyBB