【问题标题】:Magento2:Extra parameters passed to parent construct:Magento2:传递给父构造的额外参数:
【发布时间】:2018-08-29 18:19:55
【问题描述】:

我的自定义控制器中有这段代码:

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

运行命令时出现如下错误

php bin/magento setup:di:compile

Extra parameters passed to parent construct: $transportBuilder, $inlineTranslation, $scopeConfig. File:

我已从另一篇文章中遵循此代码,但我在使用该模块时没有遇到任何问题。

【问题讨论】:

    标签: php magento-2.0


    【解决方案1】:

    您正在扩展\Magento\Framework\App\Action\Action,其构造函数只有一个参数:\Magento\Framework\App\Action\Context。

    所以你应该打电话

    parent::__construct($context);
    

    而不是

    parent::__construct($context, $transportBuilder, $inlineTranslation, $scopeConfig);
    

    【讨论】:

    • 谢谢,我已经按照您提到的方式解决了这个问题。但这是你的正确答案。因此接受并投票。
    猜你喜欢
    • 2011-09-05
    • 2018-02-13
    • 2018-10-07
    • 1970-01-01
    • 2011-03-06
    • 2021-02-27
    • 1970-01-01
    • 1970-01-01
    • 2012-01-04
    相关资源
    最近更新 更多