gpt4 book ai didi

php - Magento 2 : ScopeConfig Error when I use it on\Magento\Contact\Controller\Index\Post class

转载 作者:行者123 更新时间:2023-12-05 06:33:28 24 4
gpt4 key购买 nike

首先,我扩展了联系我们的模块,我想使用 ScopeConfig 检查后端是否启用,但我遇到了这个问题。我已经尝试删除生成的文件并运行设置升级命令。

根据我的假设,我认为我的代码缺少某些东西

代码:

<?php
namespace SCI\Form\Controller\Index;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;

class Post extends \Magento\Contact\Controller\Index\Post
{
protected $scopeConfig;

public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Store\Model\StoreManagerInterface $storeManager,
ScopeConfigInterface $scopeConfig,
array $data = []
){
parent::__construct($context,$data);
$this->_scopeConfig = $scopeConfig;
$this->_storeManager = $storeManager;

}

public function ifEnabled(){
return $this->_scopeConfig->getValue('extended_contact/config/extended_contact_enabled',ScopeInterface::SCOPE_STORE);
}

public function execute()
{
die($this->ifEnabled());

return parent::execute();

}
}

注意:当我将类形式\Magento\Contact\Controller\Index\Post 更改为\Magento\Framework\App\Action\Action 时它起作用了

错误:

Fatal error: Uncaught TypeError: Argument 2 passed to Magento\Contact\Controller\Index\Post::__construct() must implement interface Magento\Contact\Model\ConfigInterface, array given, called in C:\xampp\htdocs\training\app\code\SCI\Form\Controller\Index\Post.php on line 17 and defined in C:\xampp\htdocs\training\vendor\magento\module-contact\Controller\Index\Post.php:49 Stack trace: #0 C:\xampp\htdocs\training\app\code\SCI\Form\Controller\Index\Post.php(17): Magento\Contact\Controller\Index\Post->__construct(Object(Magento\Framework\App\Action\Context), Array) #1 C:\xampp\htdocs\training\generated\code\SCI\Form\Controller\Index\Post\Interceptor.php(14): SCI\Form\Controller\Index\Post->__construct(Object(Magento\Framework\App\Action\Context), Object(Magento\Store\Model\StoreManager), Object(Magento\Framework\App\Config), Array) #2 C:\xampp\htdocs\training\vendor\magento\framework\ObjectManager\Factory\AbstractFactory.php(111): SCI\Form\Controller\Index\Post\Interceptor->__construct(Object(Magento\Framework\App\Action\Conte in C:\xampp\htdocs\training\vendor\magento\module-contact\Controller\Index\Post.php on line 49

最佳答案

您可以尝试将函数更改为以下代码以修复错误。

public function ifEnabled(){
$storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;

return $this->_scopeConfig->getValue(
'extended_contact/config/extended_contact_enabled',
$storeScope
);
}

关于php - Magento 2 : ScopeConfig Error when I use it on\Magento\Contact\Controller\Index\Post class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50715787/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com