在 joomla 3 中使用 window.location

using window.location in joomla 3

我正在做一个已经有人用 joomla 完成的项目。我必须解决其中的一些问题。

他们在 joomla 3.0 中有一个下订单组件。主页面有两个选项。一种是普通订单,另一种是特殊订单。它们以单选按钮的形式给出。每个按钮上都有onclick函数,写法如下

onclick='window.location.href=("<?php echo JRoute::_('index.php?option=com_order'); ?>")'

onclick='window.location.href=("<?php echo JRoute::_('index.php?option=com_order&ordertype=2'); ?>")'

第一个按钮将形成 url 如下。

index.php?option=com_order&view=form&layout=edit&Itemid=516&lang=en

但对于第二个 url 不正确,它给出了一些错误。

index.php?ordertype=2&option=com_order&Itemid=516&lang=en

请注意,第二个 url 缺少参数 view=form&layout=edit。我怎样才能解决这个问题?我应该添加一个新的菜单项吗?如果是什么类型?或者直接在 window.location.href 中硬编码 url?

这只是一个随机镜头,但如果您查看 JRoute-Definition here,它说有三个选项:_($url, $xhtml=true, $ssl=null)

第二个听起来很有趣:

$xhtml Replace & by & for xml compilance

也许可以将此选项设置为 false,看看你的 link 会发生什么?

代码中由此触发的部分如下所示:

if($xhtml) {
    $url = str_replace( '&', '&amp;', $url );
}

所以将此设置为 false 至少不会 str_replace &(这是我在两种情况下看到的唯一关键区别)... 我知道更换它是有原因的,但是......好吧......如果你使用的是 utf8,我想这应该不是问题......

我的意思是......另一件事,绝对奇怪的是 JRoute 似乎翻转选项和订单类型参数......无论出于何种原因。

希望我至少可以在这方面提供一些意见 :D

问候

我的第一个建议是将 &ordertype=2- 部分移出 JRoute::_() - 调用,因为这似乎会使 JRoute 感到困惑。

所以尝试使用:

onclick='window.location.href=("<?php 
  echo JRoute::_('index.php?option=com_order') . '&ordertype=2'; 
?>")'

(有点难看,不过 bquarta 可能是对的:)

谢谢大家的回答。我用了另一种方法来解决这个问题。

<?php $u = JURI::getInstance();
$u->setVar( 'ordertype', '2' );?>
onclick='window.location.href=("<?php echo JRoute::_($u->toString()); ?>")'