Missing required argument $data in magento 2

  • Some time we may get error as like below, Missing required argument $data of <MODULE BLOCK CLASS>.
  • If you are getting error then you have to validate  or check your __construct of your class.
  • $data should be array & it should be last param not middle of other param.
Correct Way is:
array $data = [] & This should last param. Should not array $data
Wrong Script:
public function __construct(
\Magento\Framework\myclass $myobjecmgt,
 array $data ,
 \Magento\Framework\ObjectManagerInterface $objectmanager
) {  ...  }
Correct way – Change script to below way
public function __construct(
\Magento\Framework\myclass $myobjecmgt,
\Magento\Framework\ObjectManagerInterface $objectmanager,
    array $data = []
) { ... }

Leave a Reply