从 cakePHP 中的 auth 获取引荐来源网址

发布于 2024-08-11 05:45:25 字数 298 浏览 2 评论 0原文

我的主页上有一个链接,只有登录后才能访问。但是,如果单击此链接,我想在登录页面上显示自定义错误消息(自定义“Message.auth”)。

即我想要(伪代码)

if (referer == '/users/reserve'){
    Message.auth = 'Please log in to reserve tickets';
}
else {
    Message.auth = 'Please log in to access that page';
}

我应该把这段代码放在哪里?

I have a link on the main page that is only accessible if they are logged in. However, if this link is clicked, I want to show a custom error message on the login page (a custom 'Message.auth').

i.e. I want (pseudo code)

if (referer == '/users/reserve'){
    Message.auth = 'Please log in to reserve tickets';
}
else {
    Message.auth = 'Please log in to access that page';
}

Where would I put this bit of code?

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

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

发布评论

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

评论(2

星星的軌跡 2024-08-18 05:45:25

如果您在登录视图中输出了身份验证闪存消息,那么这应该可以工作:

// login action of users_controller.ctp
if ($this->Session->check('Auth.redirect')
 && $this->Session->read('Auth.redirect') == '/users/reserve') {
  $this->Session->write('Message.auth', 'Please log in to reserve tickets');
}

Provided you have auth flash messages being output in the login view, this should work:

// login action of users_controller.ctp
if ($this->Session->check('Auth.redirect')
 && $this->Session->read('Auth.redirect') == '/users/reserve') {
  $this->Session->write('Message.auth', 'Please log in to reserve tickets');
}
神回复 2024-08-18 05:45:25

要获取引用,您可以调用 $this->referer() 来获取引用 URL,然后将该值传递给您的视图。

请参阅:推荐人

to get referer you can call $this->referer() to get the referring URL then pass that value to your view.

see: referer

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