我的自定义控制器中包含以下代码:
namespace Myweb\CustomArt\Controller\Index;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Filesystem;
class Form extends \Magento\Framework\App\Action\Action
{
/**
* Contact action
*
* @return void
*/
/**
* @var \Magento\Framework\Mail\Template\TransportBuilder
*/
/**
* @var Google reCaptcha Options
*/
private static $_siteVerifyUrl = "https://www.google.com/recaptcha/api/siteverify?";
private $_secret;
private static $_version = "php_7.0";
/**
* Save Form Data
*
* @return array
*/
protected $context;
private $fileUploaderFactory;
private $fileSystem;
protected $_transportBuilder;
protected $scopeConfig;
protected $inlineTranslation;
public function __construct(
\Magento\Framework\App\Action\Context $context,
Filesystem $fileSystem,
\Magento\Framework\Mail\Template\TransportBuilder $transportBuilder,
\Magento\Framework\Translate\Inline\StateInterface $inlineTranslation,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\MediaStorage\Model\File\UploaderFactory $fileUploaderFactory
) {
parent::__construct($context, $transportBuilder, $inlineTranslation, $scopeConfig );
$this->fileUploaderFactory = $fileUploaderFactory;
$this->fileSystem = $fileSystem;
$this->_transportBuilder = $transportBuilder;
$this->inlineTranslation = $inlineTranslation;
$this->scopeConfig = $scopeConfig;
}
Run Code Online (Sandbox Code Playgroud)
运行命令时出现以下错误
php bin/magento setup:di:compile
Extra parameters passed to parent construct: $transportBuilder, $inlineTranslation, $scopeConfig. File:
尽管我在模块的工作中没有遇到任何问题,但是我从另一篇文章中遵循了此代码。
小智 5
您正在扩展\Magento\Framework\App\Action\Action其构造函数只有一个参数:\Magento\Framework\App\Action\Context。
所以你应该打电话
parent::__construct($context);
Run Code Online (Sandbox Code Playgroud)
代替
parent::__construct($context, $transportBuilder, $inlineTranslation, $scopeConfig);
Run Code Online (Sandbox Code Playgroud)