从 cakePHP 中的 auth 获取引荐来源网址
我的主页上有一个链接,只有登录后才能访问。但是,如果单击此链接,我想在登录页面上显示自定义错误消息(自定义“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您在登录视图中输出了身份验证闪存消息,那么这应该可以工作:
Provided you have auth flash messages being output in the login view, this should work:
要获取引用,您可以调用 $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