Welcome Guest, Not a member yet? Register   Sign In
Problem in CI v2 -> v4 project conversion (redirection / login / other controller)

(This post was last modified: 07-16-2020, 11:52 AM by juef.)


I have an old project I'm trying to convert to CI v4 from CI v2, and I'm running into a little problem. I had an Account controller which handled the site login. In the login function, I had something like this to load the site home (for which I have a controller and view) after login:

PHP Code:

Unfortunately, using redirect gives me a forInvalidRedirectRoute HTTP exception. I tried two other solutions:
  1. return redirect()->to('home'); Unfortunately, this seems to look for a home method in the Account controller class.
  2. echo view('home'); This loads the home.php view, but without a template and all the stuff it needs from its controller. The controller is made to load some news like so:

PHP Code:
$news_model = new News_model();

$data['news'] = $news_model->get_news();
$data['view'] = 'home.php';


Obviously, I could simply copy the above code in the Account controller, but that wouldn't be elegant at all, and mostly, at some point I would love the login to redirect to the page the user was on. Obviously, it wouldn't make much sense to have basically every possible controller and view inside the login handler.

Any help or suggestion would be much appreciated. Thank you!

Try return redirect()->to('/home'); Not tested.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

Thank you very much for your reply!

Unfortunately, it did the same as my first attempted workaround described above, which is very similar to your suggestion. I'll probably end up simply doing this:

PHP Code:
return redirect()->to(base_url()); 

Theme © iAndrew 2016 - Forum software by © MyBB