0

I am following a tutorial about Magento version 2.4.2, and I am getting a problem while using Action as It shows deprecation, and also even after cleaning cache, the error shown is Required parameter 'theme_dir' was not passed

This is my code if anyone has an idea

<?php
namespace SimplifiedMagento\RequestFlow\Controller\Page;

use Magento\Framework\App\Action\Action;
use Magento\Framework\App\ResponseInterface;

class CustomNoRoute extends Action
{

    public function execute()
    {
        echo "this is our custom 404";
    }
}

The code after update

namespace SimplifiedMagento\RequestFlow\Controller\Page;

use Magento\Framework\App\ActionInterface;
use Magento\Framework\App\ResponseInterface;

class CustomNoRoute implements ActionInterface
{

    public function execute()
    {
        echo "this is our custom 404";
    }
}

I got this new error after resolving a problem related to the theme

Call to a member function get() on null in C:\xampp-clean\htdocs\magento242\vendor\magento\framework\App\Action\Action.php:109 Stack trace: #0 C:\xampp-clean\htdocs\magento242\vendor\magento\framework\App\FrontController.php(186): Magento\Framework\App\Action\Action->dispatch(Object(Magento\Framework\App\Request\Http)) #1 C:\xampp-clean\htdocs\magento242\vendor\magento\framework\App\FrontController.php

Well after changing my code to this

<?php
namespace SimplifiedMagento\RequestFlow\Controller\Page;

 use Magento\Framework\App\ActionInterface;
 use Magento\Framework\App\ResponseInterface;

class CustomNoRoute implements ActionInterface


 {

    public function execute()
    {
        echo "this is our custom 404";
     }
   }

I am getting this output :

this is our custom 4041 exception(s):
Exception #0 (InvalidArgumentException): Invalid return type

Exception #0 (InvalidArgumentException): Invalid return type
<pre>#1 Magento\Framework\App\Http\Interceptor->launch() called at [vendor\magento\framework\App\Bootstrap.php:263]
#2 Magento\Framework\App\Bootstrap->run() called at [pub\index.php:29]
</pre>

So at least it is echoing the result ;

Thanks in advance

2
  • What you want to do with controller? I mean what action perform by controller? Aug 23, 2021 at 6:47
  • Showing 404 error
    – askcoder
    Aug 27, 2021 at 14:50

3 Answers 3

1

You should implement Magento\Framework\App\ActionInterface instead of extending Magento\Framework\App\Action\Action.

Depending on the purpose of your Action, you can also use a more specific interface like Magento\Framework\App\Action\HttpGetActionInterface to limit the Action to specific requests types.

Example:

...
use Magento\Framework\App\Action\HttpGetActionInterface;

class Index implements HttpGetActionInterface
{
...

For more information about Action classes, take a look in the Magento DevDocs.

Also, you cannot just use echo to output something on the page from an Action. See Result object in the DevDocs for possible return values. You might want to return a page result object that will render a specific page defined using layout XML and phtml templates. You could also use raw for testing purposes like outputting a simple string.

3
  • Thanks but I am still having , the same problem , check my code updated
    – askcoder
    Aug 26, 2021 at 20:36
  • I got this new errror
    – askcoder
    Aug 26, 2021 at 20:53
  • Call to a member function get() on null in C:\xampp-clean\htdocs\magento242\vendor\magento\framework\App\Action\Action.php:109 Stack trace: #0 C:\xampp-clean\htdocs\magento242\vendor\magento\framework\App\FrontController.php(186): Magento\Framework\App\Action\Action->dispatch(Object(Magento\Framework\App\Request\Http)) #1 C:\xampp-clean\htdocs\magento242\vendor\magento\framework\App\FrontController.php
    – askcoder
    Aug 26, 2021 at 20:53
0

This error is not cause of controller I guess, Please check that all the rows in the table has value 0 for type field (especially activated theme).

magento_database -> theme.

enter image description here

1
  • This is the new error : Error: Call to a member function get() on null in C:\xampp-clean\htdocs\magento242\vendor\magento\frame
    – askcoder
    Aug 27, 2021 at 10:36
0

Try code like this one :

namespace SimplifiedMagento\RequestFlow\Controller\Page;


class CustomNoRoute extends \Magento\Framework\App\Action\Action
{

     public function __construct(
       \Magento\Framework\App\Action\Context $context,
       \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory
     ) {
        $this->resultForwardFactory = $resultForwardFactory;
        parent::__construct($context);
     }

    public function execute()
    {
        echo "this is our custom 404";
    }
}
1

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.