В сетке продуктов указано "Ресурс не установлен" при добавлении конструкции в класс модели
У меня есть класс модели, в который я пытаюсь внедрить интерфейс scopeconfig, и после компиляции di в сетке продуктов говорится "Ресурс не установлен". Мой класс расширяется
\Magento\Framework\Model\AbstractModel
и реализует \Magento\Framework\DataObject\IdentityInterface
, \myCompany\myModule\Api\Data\MyEntityInterface
.
Ошибки в 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. [] []
Единственное, что я добавил в класс, - это новый код __construct()
. Вот мой код.
protected function _construct() {
$this->_init('\myCompany\myModule\Model\ResourceModel\MyEntity');
}
public function __construct(
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
) {
$this->_scopeConfig = $scopeConfig;
}
3
1 answers
Я не был согласен с конструктором родительского класса. Удивительно то, что настройка magento:di:компиляция не привела к ошибке. В любом случае, вот решение.
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);
}
10
Author: Joseph Hovik, 2017-03-21 14:21:15