在 joomla 中返回上一页 [英] Return to previous page in joomla

查看:20
本文介绍了在 joomla 中返回上一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了自己的扩展程序.可以从网站的不同组件和部分访问此扩展程序.

我遇到的问题是可能有许多不同的 URL 链接到此扩展程序.我有一个取消"按钮,但我不知道如何让这个按钮链接到上一个 URL.

想知道 joomla 中是否内置了类似 getPreviousURL 的功能?找不到任何东西.

我应该说我仍然希望能够运行我的 cancel() 方法.例如index.php?option=com_mycomp&task=mycomp.cancel.然后取消() 方法将执行重定向到上一页.

解决方案

如果我理解你的问题是正确的,这肯定会帮助你.Joomla 不支持类似的东西,但 Javascript 支持.

JS

HTML

<块引用>

back() 方法加载历史列表中的前一个 URL.这是与单击后退按钮或 history.go(-1) 相同.

根据需要更新答案.

PHP

如果 JavaScript 不可行,您可以使用 HTTP_REFERER,对其进行清理,然后通过 PHP 将其回显.

setRedirect($url);?>

<块引用>

如果

这将不起作用
  • 在浏览器地址栏中输入了站点 URL.
  • 通过浏览器维护的书签访问了该网站.
  • 作为窗口/选项卡中的第一页访问了该网站.
  • 安装了安全软件(防病毒/防火墙/等),可从所有请求中去除引用.
  • 以编程方式(例如 curl)访问了该站点,而无需设置引用标头(搜索机器人!).

如果您遇到任何问题,请告诉我.

更新答案 - Joomla 方法

$url = JFactory::getURI();$request_url = $url->toString();

I have created my own extension. This extension can be accessed from different components and parts of the website.

The problem I have is that there could be a number of different URLs that link to this extension. I have a 'cancel' button and I can't work out how I would get this button to link to the previous URL.

Wondering if there is something built into joomla like getPreviousURL? Couldn't find anything.

EDIT: I should have said that I still want to be able to run my cancel() method. e.g. index.php?option=com_mycomp&task=mycomp.cancel. The cancel() method will then perform a redirection to the previous page.

解决方案

If I understand your question right, This will help you out for sure. Joomla does not support something like that but Javascript does.

JS

<script>
function goBack()
  {
  window.history.back()
  }
</script>

HTML

<input type="button" value="Cancel" onclick="goBack()" />

The back() method loads the previous URL in the history list. This is the same as clicking the Back button or history.go(-1).

Updated Answer as required.

PHP

If JavaScript isn't a possibility, you could use the HTTP_REFERER, sanitize it, and echo it out via PHP.

<?php
  $url = htmlspecialchars($_SERVER['HTTP_REFERER']);
  $this->setRedirect($url);
?>

This will not work if

  • entered the site URL in browser address bar itself.
  • visited the site by a browser-maintained bookmark.
  • visited the site as first page in the window/tab.
  • has security software installed (antivirus/firewall/etc) which strips the referrer from all requests.
  • visited the site programmatically (like, curl) without setting the referrer header (searchbots!).

If you come across any problems let me know.

Update answer - Joomla method

$url = JFactory::getURI();
$request_url = $url->toString();

这篇关于在 joomla 中返回上一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆