Passing variables in the joomla component
I am trying to create a simple joomla component to show custom google search results based on this API. How to pass get variable to joomla component? Let's say I already have the basics of what is calling the custom view index.php?option=com_google&view=google
, what I would like to pass a variable to it 'q' $_GET
, what should the url query string look like?
source to share
An HTTP requestGET
works with a URL, so variables are always passed in the request URL.
To add q
to the current url, just add &q=SomeValue
where SomeValue
the percentage or url was appropriately .
Joomla 1.5
If you are using Joomla! 1.5 you can use JRequest
to get the value of any variable regardless of whether it is posted POST
or GET
see this document about finding a query variable .
$q = JRequest::getVar('q');
Joomla 1.6 +
For Joomla! 1.6+ is recommended to use JInput
for retrieving query data as it is JRequest
depreciated, but for Joomla! 3.0+ you MUST use JInput
as it JRequest
has funcitonality removed and will continue to disappear over the next few releases.
To use JInput
, you can either get the current object or chain through the current Joomla app to retrieve the variables.
Receiving JInput
$jAp = JFactory::getApplication(); // Having the Joomla application around is also useful
$jInput = $jAp->input; // This is the input object
$q = $jInput->get('q'); // Your variable, of course get() support other option...
Use JInput
through a chain
$jAp = JFactory::getApplication(); // Having the Joomla application around is also useful
$q = $jAp->input->get('q'); // Your variable
source to share