Search code examples
joomla4

How to get request method in Joomla 4


I am wondering why such a simple thing turns compilated in Joomla 4.

I have a URL call. Inside my custom extension, I need to know the request method, GET or POST. For instance, I need to retrieve REQUEST_METHOD data in $_SERVER array. But I wasn't able.

How can I do that?

Thanks Jaime


Solution

  • The Input object has a getMethod method. Note the method is returned as an uppercase string.

    Example usage:

    use Joomla\CMS\Factory;
    
    $app = Factory::getApplication(); 
    $input = $app->input;
    
    if($input->getMethod() == "HEAD"){return;}