Disclaimer: I don't know the first thing about Joomla.
Looking at the documentation, JRequest::getVar
fetches values from GET or POST parameters and is supposed to be used like JRequest::getVar('amount')
(note the argument is a string, not a variable). echo $amount
and echo JRequest::getVar($amount)
are of course nowhere near equivalent, the former means "echo the value of $amount
", the latter "echo the value of a GET or POST variable with the name of the value of $amount
."
The second parameter $default
is also very useful:
$amount = JRequest::getVar('amount', 100);
// is roughly equivalent to:
if ($_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET['amount'])) {
$amount = $_GET['amount'];
} else if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['amount'])) {
$amount = $_POST['amount'];
} else {
$amount = 100;
}
Even without the second parameter though, it'll take care of variable cleaning and (un)escaping where necessary, so it's a good idea to use this function to read request parameters.