PHP Joomla! 6 Joomla! 5 Joomla! 3 (Legacy) Component Basic

Read and Sanitize Request Input with $app->getInput() (GET, POST, JSON)

Replaces raw $_GET/$_POST and deprecated $app->input with strongly filtered $app->getInput() accessors.

Updated on 24 November 2026 49 copies 174 views
components/com_example/src/Controller/ApiController.php
<?php

declare(strict_types=1);

use Joomla\CMS\Factory;

$input   = Factory::getApplication()->getInput();
$id      = $input->getInt('id', 0);
$sort    = $input->getCmd('sort', 'featured');
$query   = trim($input->getString('q', ''));
$payload = $input->json->getArray(); // Corpo application/json
getCmd() allows only [A-Za-z0-9._-], making it ideal for views, tasks and sort keys.
components/com_example/src/Controller/ApiController.php
<?php
$input = JFactory::getApplication()->input;
$id    = $input->getInt('id', 0);
$sort  = $input->getCmd('sort', 'featured');
$query = $input->getString('q', '');
Legacy Joomla 3 version via JFactory::getApplication()->input.

Technical explanation and best practices

In Joomla 6, accessing $app->input directly triggers a deprecation notice. Use $app->getInput() with the strictest matching filter (getInt, getCmd, getString or json).

Direct Engineering

Have a Joomla project or technical challenge in mind?

From architectural diagnosis to production deployment, directly with the engineer.