从URL重写获取选项 [英] Getting options from URL rewriting

查看:39
本文介绍了从URL重写获取选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经继承了Joomla网站,并试图了解其所有工作原理.有一些旧代码在Joomla 2.5中有效,而在Joomla 3.7中不再有效.原始代码从$ _GET中提取URL信息以构建要显示的页面的正确链接,如下所示:

I've inherited a Joomla site and I'm trying to learn how it all works. There's legacy code that works in Joomla 2.5 that no longer works in Joomla 3.7 The original code pulls the URL info from $_GET to build the correct link of the page to display, like this:

$search_str = array();
foreach ($_GET as $get_key => $get_value) {
    array_push($search_str, $get_key . '=' . $get_value);
}

它在2.5中可以正常工作,但在3.7中不返回任何内容.我正在尝试确定完成同一件事的新方法.我已经研究了JURI和其他各种类/函数,但似乎找不到任何帮助.

It works fine in 2.5 but nothing is returned in 3.7. I am trying to determine the new method of accomplishing the same thing. I've lookat at JURI and a variety of other class/functions but can't seem to find anything to help.

推荐答案

要访问url变量,请使用;

To access url variables use;

$app = JFactory::getApplication();
$var = $app->input->get(VARIABLE, DEFAULT);

不过,不要期望该URL是SEO友好的,为此您需要创建路由器- https://docs.joomla.org/Supporting_SEF_URLs_in_your_component

Dont expect the url to be SEO friendly though, for that you need to create a router - https://docs.joomla.org/Supporting_SEF_URLs_in_your_component

编辑

戴尔.如果您die(print_r(JFactory::getApplication()->input));并查看数据对象,您将看到它的属性是您期望的url部分,但是它们是受保护的,因此您不能直接调用该数据对象.相反,您需要像这样单独使用它们;

Hi Dale. If you die(print_r(JFactory::getApplication()->input)); and look at the data object you'll see its attributes are the url parts you are expecting, but they are protected so you cant just call the data object directly. Instead you need to use call them individually, like so;

$app    = JFactory::getApplication();

$option = $app->input->get('option');
$view   = $app->input->get('view');
$layout = $app->input->get('layout');
$id     = $app->input->get('id');
$Itemid = $app->input->get('Itemid');

这篇关于从URL重写获取选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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