Reputation: 4721
is there a way in Kohana3 to reference the previous controller/action.
Let me explain a little better:
I have a base controller which check if user is logged into the system using the Auth module.
If the user goes to a page which he is not allowed to view, he gets redirected to the logins screen.
Now I would like (when he sings in) to go back to the page which triggered the login controller.
I wanted to pass it as an URI segment, but the problem is that the controller can contain "/" characters.
Example:
mysite.com/user/profile
mysite.com/login
(need to pass user/profile)mysite.com/user/profile
Upvotes: 0
Views: 200
Reputation: 13430
I do this by constantly updating a session value for users who are not logged in.
Session::instance()->set('redirect', Request::instance()->uri());
Then, after a successful login, you can redirect like this:
Request::instance()->redirect(Session::instance()->get('redirect', URL::base());
I haven't tested the code, but the concept is there. If no value is set then proceed to redirect to the home page.
Please make sure you're careful and validate the redirect URL. It shouldn't be, but since we're dealing with user data there's always a slight chance something bad might come back. The last thing you want is to be redirected to a virus infested website after you've logged in.
Upvotes: 2