0

I start learning magneto 2. I give it a try with Max Pronko's videos. Figure out some of the codes that are outdated, deprecated. Here is my controller. Any suggestion on how to use ActionInterface here.

<?php
declare(strict_types=1);
namespace Isuru\FirstPage\Controller\Page;

use Magento\Framework\App\Action\Action;
use Magento\Framework\Controller\Result\Json;
use Magento\Framework\Controller\ResultFactory;

class View extends Action
{
    public function execute()
    {
        /** @var Json $jsonResult */
        $jsonResult = $this->resultFactory->create(ResultFactory::TYPE_JSON);
        $jsonResult->setData([
            'message' => 'First Page'
        ]);
        return $jsonResult;ActionInterface
    }
}

enter image description here

strong text

1

1 Answer 1

7

The class \Magento\Framework\App\Action\Action is deprecated in the latest version of the Magento. Instead of you should use the GET or POST interface as per your request type

  1. \Magento\Framework\App\Action\HttpGetActionInterface
  2. \Magento\Framework\App\Action\HttpPostActionInterface

These both interface extends \Magento\Framework\App\ActionInterface

So your sample controller should look like this

<?php

namespace Vendor\Module\Controller\Index;


class Index implements HttpGetActionInterface
{
    public function execute()
    {
        // code ..
    }
}
3
  • Thanks for your answer. Can we use ActionInterface directly? Apr 29, 2021 at 9:57
  • Yes, we can use but as per Magento standard, we should use the GET to POST action interface instead of direct use. Apr 29, 2021 at 9:58
  • Got it and working. Thanks Apr 29, 2021 at 10:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.