3
public function storeans()
{
    $user   = JFactory::getUser();
    $post   = JRequest::getVar('post');
}    

In the above code, JRequest is deprecated.

What is the equivalent that can be used in Joomla 3.x?

8

JRquest has been deprecated in the earlier release of Joomla 3.x

Use JFactory::getApplication()->input instead.

For getting any variable (say name) from post method use below line of code

JFactory::getApplication()->input->post->get('name');
  • JFactory::getApplication()->input->post->get('name'); use this i can't get the values. If any solution is there – user3604 Mar 4 '15 at 9:09
  • 1
    If you want to collect all the data posted then use JFactory::getApplication()->input->post->getArray(array())l as @Lodder has suggested. If it is not working then please share your code. – Nick Mar 4 '15 at 10:24
  • JRequest was deprecated in Joomla 2.5 actually and JInput was also introduced then. However note that JInput was not compatible with having magic quotes enabled so it wasn't used by core in 2.5. However if you're extension needs 2.5/3.x compatibility it is available – George Wilson Mar 4 '15 at 16:38
4

Firstly, I'll just say that you need to use JInput. More information on this can be read about here:

https://docs.joomla.org/Retrieving_request_data_using_JInput

So to start off with: you need to call JInput via the application like so:

$jinput = JFactory::getApplication()->input;

Then, if you wish to get a single value, you can use:

$name = $jinput->get('name');

Or if you wish to get an array of data, let's say from a form with multiple fields, then you can use:

$data = $jinput->post->getArray(array());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy