Redirect 乔姆拉·塞特兰';行不通
我有一个简单的Joomla控制器,但我不能重定向任何东西 根据文件:Redirect 乔姆拉·塞特兰';行不通,redirect,joomla,joomla2.5,joomla-extensions,Redirect,Joomla,Joomla2.5,Joomla Extensions,我有一个简单的Joomla控制器,但我不能重定向任何东西 根据文件: class MyController extends MyBaseController { function import() { $link = JRoute::_('index.php?option=com_foo&ctrl=bar'); $this->setRedirect($link); } } //The url contains & html escaped
class MyController extends MyBaseController {
function import() {
$link = JRoute::_('index.php?option=com_foo&ctrl=bar');
$this->setRedirect($link);
}
}
//The url contains & html escaped character instead of "&"
这应该行得通,但我的URL格式不正确。这里有我遗漏的东西吗?为什么Joomla要将所有的“&”字符转换成&代码>?我应该如何使用setRedirect
谢谢好的,我修好了。因此,如果有人需要它:
而不是
$link = JRoute::_('index.php?option=com_foo&ctrl=bar');
$this->setRedirect($link);
使用
让它工作。很高兴您找到了答案,顺便说一句,JRoute::uz()
中的布尔参数默认为true,对于xml遵从性非常有用。它所做的是,在静态方法中,它使用htmlspecialchars php函数,如下所示:$url=htmlspecialchars($url)
替换&for xml。试试这个
$mainframe = &JFactory::getApplication();
$mainframe->redirect(JURI::root()."index.php?option=com_foo&ctrl=bar","your custom message[optional]","message type[optional- warning,error,information etc]");
检查Joomla震源后,您可以快速了解发生这种情况的原因:
if (headers_sent())
{
echo "<script>document.location.href='" . htmlspecialchars($url) . "';</script>\n";
}
else
{
... ... ...
if(headers\u sent())
{
echo“document.location.href=”.htmlspecialchars($url)。“;\n”;
}
其他的
{
... ... ...
问题是您的页面可能已经输出了一些数据(通过echo或其他方式)。
在这种情况下,Joomla被编程为使用一个简单的javascript重定向
一个简单的解决方案是不使用Joomlas函数,直接以更有意义的方式编写javascript:
echo "<script>document.location.href='" . $url . "';</script>\n";
echo“document.location.href=”。$url.“;\n”;
这对我有用:)/libraries/joomla/application/application.php
查找第400行
// If the headers have been sent, then we cannot send an additional location header
// so we will output a javascript redirect statement.
if (headers_sent())
{
echo "<script>document.location.href='" . htmlspecialchars($url) . "';</script>\n";
}
//如果已发送头,则无法发送其他位置头
//因此,我们将输出一个javascript重定向语句。
如果(已发送的头)
{
echo“document.location.href=”.htmlspecialchars($url)。“;\n”;
}
取代
// If the headers have been sent, then we cannot send an additional location header
// so we will output a javascript redirect statement.
if (headers_sent())
{
echo "<script>document.location.href='" . $url . "';</script>\n";
}
//如果已发送头,则无法发送其他位置头
//因此,我们将输出一个javascript重定向语句。
如果(已发送的头)
{
echo“document.location.href=”$url.“;\n”;
}
这很有效!我同意你的答案@jobin cause$This->setRedirect($link);setRedirect()未在自定义类中定义,因此请使用jobin answer它确实有效实际上我有它,只是我在JController和我自己的控制器之间放置了一个控制器,以便我自己的控制器可以共享某些函数。但感谢这是最糟糕的解决方案。永远不要修改第三方库来修复不是bug的东西。除非您觉得舒服,否则我会如果请求核心Joomla人员合并您的更改,您不应该进行更改。事实上,您可能正在可怕地破坏应用程序的其余部分,并从根本上改变其他第三方库可能依赖的Joomla行为。
// If the headers have been sent, then we cannot send an additional location header
// so we will output a javascript redirect statement.
if (headers_sent())
{
echo "<script>document.location.href='" . $url . "';</script>\n";
}