- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
首先,我扩展了联系我们的模块,我想使用 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/
我正在研究 Magento 2。 但找不到在布局 xml 文件中获取 scopeconfig 值的解决方案。 在 magento 1.x 中,使用如下。 在 magento 2 中,如何
首先,我扩展了联系我们的模块,我想使用 ScopeConfig 检查后端是否启用,但我遇到了这个问题。我已经尝试删除生成的文件并运行设置升级命令。 根据我的假设,我认为我的代码缺少某些东西 代码: _
我是一名优秀的程序员,十分优秀!