【问题标题】:Magento call to a member function get() on nullMagento 在 null 上调用成员函数 get()
【发布时间】:2021-10-27 07:43:17
【问题描述】:

我正在使用 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>

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

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

【问题讨论】:

    标签: php zend-framework magento2 magento2.4


    【解决方案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/ 生成/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-21
      • 2021-01-23
      • 2017-09-14
      • 1970-01-01
      • 1970-01-01
      • 2015-03-29
      • 2017-08-09
      • 2020-03-10
      相关资源
      最近更新 更多