问题
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