Magento2 - Missing required argument
In your constructor you are calling parent::construct()
, but you are not extending any class. You must extend the class to which you are override or to the class \Magento\Framework\View\Element\Template
and there is a typo in constructor name (two underscores are missing), the proper name is __construct
Also, write your constructor this way:
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Store\Model\StoreManagerInterface $storeManager,
array $data = []
){
$this->_storeManager = $storeManager;
return parent::__construct($context, $data);
}
I was having the same error, all my __constructs and Extending's are correct, if you are scratching your head wondering... why when I do:
php bin/magento setup:upgrade
it breaks everything and get this error, but then when I do:
php bin/magento setup:di:compile
the same code works fine afterwards, but then would break again if you do another:
php bin/magento setup:upgrade
??
Then most likely is that you have got your array $DATA in the middle of your Construct definition, this would cause this issue and the solution is to move this right to the end of your __constrct definition, see example below:
Example, this will NOT work:
public function __construct (
\Magento\Framework\Model\Context $ModelContext,
array $Data = [],
\Magento\Framework\Registry $Registry
But this will work:
public function __construct (
\Magento\Framework\Model\Context $ModelContext,
\Magento\Framework\Registry $Registry,
array $Data = []
I hope this helps.