3

I have a model class that I'm trying to inject a ScopeConfigInterface into, and after compiling di, the product grid says "The resource isn't set." My class extends \Magento\Framework\Model\AbstractModel and implements \Magento\Framework\DataObject\IdentityInterface, \myCompany\myModule\Api\Data\MyEntityInterface.

Errors in var/system.log:

[2017-03-15 22:36:51] main.CRITICAL: Broken reference: the 'header' tries to reorder itself towards 'global.notices', but their parents are different: 'page.wrapper' and 'notices.wrapper' respectively. [] []
[2017-03-15 22:36:51] main.CRITICAL: Broken reference: the 'page.breadcrumbs' tries to reorder itself towards 'notifications', but their parents are different: 'page.wrapper' and 'notices.wrapper' respectively. [] []
[2017-03-15 22:36:51] main.CRITICAL: Broken reference: the 'global.search' tries to reorder itself towards 'notification.messages', but their parents are different: 'header.inner.right' and 'header' respectively. [] []
[2017-03-15 22:36:51] main.CRITICAL: The resource isn't set. [] []

The only thing I've added to the class is the new __construct() code. Here is my code.

protected function _construct() {
    $this->_init('\myCompany\myModule\Model\ResourceModel\MyEntity');
}

public function __construct(
    \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
) {
    $this->_scopeConfig = $scopeConfig;
}

enter image description here

1 Answer 1

11

I wasn't in accord with the parent class' constructor. The surprising thing is magento setup:di:compile yielded no error. Anyway, here's the solution.

public function __construct(
        \Magento\Framework\Model\Context $context,
        \Magento\Framework\Registry $registry,
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
        \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
        \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
        array $data = []
    ) {
        $this->_scopeConfig = $scopeConfig;
        parent::__construct($context, $registry, $resource, $resourceCollection, $data);
    }
1
  • setup:di:compile worked for me.
    – fudu
    Apr 14, 2021 at 8:49

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.