Zend Framework - 创建智能后退按钮
我想要一个按钮,根据用户在网站上的位置,它调用适当的控制器和操作。
我有一个带有后退按钮的页面。
人们可以通过以下方式到达该页面:
a) 主页上的链接。 或者 b) 通过另一个页面上的链接(同一站点内)。
如果用户来自主页,则后退按钮应指向该控制器和操作。
但是,如果用户来自其他页面,则后退按钮应指向另一个控制器和操作。
我们怎样才能完成这样的事情?
非常感谢,
MEM
ps - 历史返回没有用,因为我们不能允许该按钮链接到外部站点。
I would like to have a button that depending on where the user was on the site, it calls the appropriate controller and action.
I have a page with a back button.
People can arrive on that page trough:
a) link on the homepage.
OR
b) trough a link on another page (inside the same site).
If the user comes from the homepage, the back button should point to that controller and action.
If, however, the user comes from that other page, the back button should point to another controller and action.
How can we accomplish something like this?
Thanks a lot,
MEM
ps - History Back is of no use, because we cannot allow that button to link to an external site.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,如果您无法使用 javascript 返回历史记录,那么当某些外部站点直接引导到该页面时,您就会遇到未定义的情况。我们假设,如果用户通过外部站点到达该页面,则后退按钮应该不会出现。
考虑检查
$_SERVER['HTTP_REFERER']
并基于此构建后退按钮链接。检查引荐来源网址(parse_url() 可能在这里有特殊服务),如果它不是您的域,请不要'不要显示该按钮,否则,选择某个位置将用户“返回”到(可能只是整个引用 URL)。Well, if you can't use javascript to go back in the history, then you have an undefined case when some external site leads directly to the page. Let's assume that if the user arrived at the page via an external site, the back button should simply not appear.
Consider checking the
$_SERVER['HTTP_REFERER']
and constructing the back button link based on that. Inspect the referer (parse_url() may be of particular service here), if it's not your domain, don't display the button, otherwise, pick someplace to send the user "back" to (probably just the whole referer URL).