从 URL 重写中获取选项

2022-01-06 00:00:00 php joomla

我继承了一个 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');

相关文章