6

I'm a beginner in Joomla and a little confused with this method.

for example consider this : $app->input->get('foo',0,'int');

where is the source of foo ?

JInput->get() get's inputs from where ?

1 Answer 1

5

Source of foo are the PHP superglobals such as $_POST or $_GET. So it's data what the user submits via a form, URL or cookie to your component.

So you are receiving in a safe way a parameter that was sent to you via a HTTP method.

This:

$myVar = $app->input->get('foo',0,'int');

is largely equivalent to:

$myVar = (int) $_REQUEST['foo'];

You should always use JInput, no matter what. You just forget about the PHP superglobals. Read the whole documentation in silence, you should know it by heart.

3
  • To avoid any warning, it's better to check if $_REQUEST['foo'] is set: $myVar = isset($_REQUEST['foo'] ? (int) $_REQUEST['foo'] : 0;
    – Farahmand
    Commented Aug 27, 2014 at 7:27
  • What warning? The code with request is just an example, not something to use. Commented Aug 27, 2014 at 7:31
  • Yes, my comment is about a general PHP rule to avoid PHP warnings and not a Joomla one. I wanted to say that $myVar = $app->input->get('foo',0,'int'); is equivalent to $myVar = isset($_REQUEST['foo'] ? (int) $_REQUEST['foo'] : 0;.
    – Farahmand
    Commented Aug 27, 2014 at 7:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.