1

I have a controller in my custom module, but when i run php bin/magento setup:di:compile, i got this following error:

Extra parameters passed to parent construct: $coreRegistry

here's my controller code:

use Magento\Framework\Exception\LocalizedException;

class Save extends \Magento\Backend\App\Action
{

    protected $dataPersistor;

    /**
     * @param \Magento\Backend\App\Action\Context $context
     * @param \Magento\Framework\App\Request\DataPersistorInterface $dataPersistor
     */
    public function __construct(
        \Magento\Backend\App\Action\Context $context,
        \Magento\Framework\Registry $coreRegistry,
        \Magento\Framework\App\Request\DataPersistorInterface $dataPersistor
    ) {
        $this->dataPersistor = $dataPersistor;
        parent::__construct($context, $coreRegistry);
    }
}
1

As you extentd the class \Magento\Backend\App\Action which is inherited from \Magento\Backend\App\AbstractAction. Here if you see the constructor,only one parameter takes. But you passed two parameter. Thats why you getting this error. You can try the following code:

use Magento\Framework\Exception\LocalizedException;

class Save extends \Magento\Backend\App\Action
{

protected $_dataPersistor;
protected $_coreRegistry;

/**
 * @param \Magento\Backend\App\Action\Context $context
 * @param \Magento\Framework\App\Request\DataPersistorInterface $dataPersistor
 */
public function __construct(
    \Magento\Backend\App\Action\Context $context,
    \Magento\Framework\Registry $coreRegistry,
    \Magento\Framework\App\Request\DataPersistorInterface $dataPersistor
) {
    $this->_coreRegistry= $coreRegistry;
    $this->_dataPersistor = $dataPersistor;
    parent::__construct($context);
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.