Generally when we develop PHP scripts, we work extensively with the request hashes: $_GET
, $_POST
, $_FILES
, $_COOKIE
, and $_REQUEST
. In Joomla!, instead of directly using these, we use the static JRequest
class. We use this because it allows us to process the input at the same time as retrieving it, this decreases the amount of code required and helps improve security.
The request hashes $_GET
, $_POST
, $_FILES
, $_COOKIE
, and $_REQUEST
are still available, and in cases where we are porting existing applications we need not change the use of these hashes.
The two methods that we use the most are JRequest::setVar()
and JRequest::getVar()
. As the names suggest, one accesses request-data and the other sets it. In this example, we get the value of id
; if id
is not set, we return a default value, 0
(the default value is optional).
$id = JRequest::getVar('id', 0);
The JRequest::setVar()
method is used to set values in the request hashes. In comparison to the JRequest::getVar...