Getting options from URL rewriting

社会主义新天地 提交于 2021-02-08 07:45:23

问题


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);
}

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.


回答1:


To access url variables use;

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

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

EDIT

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');


来源:https://stackoverflow.com/questions/45152415/getting-options-from-url-rewriting

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!