0

如果有人对此有任何想法,我正在使用 Magento 2.4 自定义错误 404 提供的错误:

Error: 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(118): Magento\Framework\App\FrontController->processRequest(Object(Magento\Framework\App\Request\Http), Object(SimplifiedMagento\RequestFlow\Controller\Page\CustomNoRoute\Interceptor))

这是功能(控制器)

<?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";
    }
}

将代码更改为此后

<?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";
    }
}

我得到这个结果:

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>

所以至少它呼应了结果;但仍然显示异常错误。

如果有人有想法?提前致谢

4

1 回答 1

-1

将您的代码更改为此它将无任何例外地回显结果。

<?php

namespace SimplifiedMagento\RequestFlow\Controller\Page;

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

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

运行以下命令-:

  1. rm -rf var/ 生成/
  2. php bin/magento s:d:c
  3. php bin/magento s:s:d -f
  4. chmod -R 777 var/ 生成/
于 2021-08-28T04:53:46.863 回答