Kohana3参考以前的控制器?

发布于 2024-10-28 03:33:16 字数 405 浏览 2 评论 0原文


Kohana3 中有没有办法引用以前的控制器/操作。

让我更好地解释一下:
我有一个基本控制器,它检查用户是否使用身份验证模块登录系统。
如果用户进入不允许查看的页面,他会被重定向到登录屏幕。

现在我想(当他唱歌时)返回到触发登录控制器的页面。
我想将它作为 URI 段传递,但问题是控制器可以包含“/”字符。

示例:

  • 用户访问 mysite.com/user/profile
  • 他被重定向到 mysite.com/login(需要传递 user/profile
  • 成功登录后,用户将被重定向回 mysite.com/user/profile

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:

  • user goes to mysite.com/user/profile
  • he gets redirected to mysite.com/login (need to pass user/profile)
  • after successful login user gets redirected back to mysite.com/user/profile

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

想挽留 2024-11-04 03:33:16

我通过不断更新未登录用户的会话值来做到这一点。

Session::instance()->set('redirect', Request::instance()->uri());

然后,在成功登录后,您可以像这样重定向:

Request::instance()->redirect(Session::instance()->get('redirect', URL::base());

我还没有测试代码,但概念是存在的。如果未设置任何值,则继续重定向到主页。

请务必小心并验证重定向 URL。不应该如此,但由于我们正在处理用户数据,因此总是有可能出现一些不好的情况。您最不想看到的就是在登录后被重定向到受病毒感染的网站。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文