fefe
fefe

Reputation: 9065

passing get variables in joomla component

I'm trying to build a simple joomla component what would show custom google search results based on it's API. How would I pass a get variable to a joomla component? Lets say I have already the basics what calls a custom view index.php?option=com_google&view=google, than I would like to pass 'q' $_GET variable to it how should the url query string look like ?

Upvotes: 3

Views: 8149

Answers (2)

Craig
Craig

Reputation: 9330

The HTTP request method GET, works with the URL, so variables are always passed in the URL of the request.

To add q to your current URL you simply add &q=SomeValue where SomeValue has been appropriately percent or URL encoded.

Joomla 1.5

If you're using Joomla! 1.5 you can use JRequest to get the value of any variable whether submitted by POST or GET, see this document on retrieving request variable.

$q = JRequest::getVar('q');

Joomla 1.6+

For Joomla! 1.6+ it is recommended to use JInput to retrieve request data as JRequest is depreciated, and for Joomla! 3.0+ you MUST use JInput as 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 use chaining through the current Joomla application to retrieve variables.

Getting 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...

Using JInput via chaining

$jAp = JFactory::getApplication();  // Having the Joomla application around is also useful
$q = $jAp->input->get('q');  // Your variable

Upvotes: 6

Martin
Martin

Reputation: 10563

You can retrieve GET vars in Joomla using:

$q = JRequest::getVar( 'q' );

This would work for a url string as per below:

index.php?option=com_google&view=google&q=some_variable

Upvotes: 1

Related Questions