This approach is deprecated because of the favor of composition over inheritance.
So instead of:
class YourClass extends \Magento\Framework\App\Action\Action
use:
class YourClass implements \Magento\Framework\App\ActionInterface
and add your logic to the execute()
method.
It's true though that there's still a lot of Magento core code that uses the deprecated approach. So this will not be removed soon, if they will ever do.
Edited Date :- 3rd June, 2022
you can use Magento\Framework\App\ActionInterface
directly but, as per Magento standard, you should use the HTTP Method interface (GET, POST, PUT, DELETE) as per your request type
\Magento\Framework\App\Action\HttpGetActionInterface
\Magento\Framework\App\Action\HttpPostActionInterface
\Magento\Framework\App\Action\HttpPutActionInterface
\Magento\Framework\App\Action\HttpDeleteActionInterface
These HttpHTTP MethodActionInterface interfaces extends \Magento\Framework\App\ActionInterface.
your sample controller should look like this
<?php
namespace Vendor\ModuleName\Controller\Index;
use Magento\Framework\App\ActionInterface;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\View\Result\PageFactory;
class Display implements HttpGetActionInterface
{
/**
* @var PageFactory
*/
private $pageFactory;
/**
* @var RequestInterface
*/
private $request;
public function __construct(PageFactory $pageFactory, RequestInterface $request)
{
$this->pageFactory = $pageFactory;
$this->request = $request;
}
public function execute()
{
// Get the params that were passed from our Router
// echo $firstParam = $this->request->getParam('first_param', null);
return $this->pageFactory->create();
}
}
for more details about routing action class see here at Magento docs