当我放弃model.Here时,我有例外--这是一个例外:
1 exception(s):
Exception #0 (InvalidArgumentException): Training4\Vendor\Model\Training4_Vendor2Product does not extend \Magento\Framework\DataObject
Exception #0 (InvalidArgumentException): Training4\Vendor\Model\Training4_Vendor2Product does not extend \Magento\Framework\DataObject
Magento版本为2.4.4 \Training4\Vendor\Model\Training4_Vendor2Product
<?php
namespace Training4\Vendor\Model;
use Magento\Framework\Model\AbstractModel;
class Training4_Vendor2Product extends AbstractModel
{
const vendor_id='id';
protected $_idFieldName = self::vendor_id;
protected function _construct()
{
$this->_init(\Training4\Vendor\Model\ResourceModel\Training4_Vendor2Product::class);
}
}
\Training4\Vendor\Model\ResourceModel\Training4_Vendor2Product
<?php
namespace Training4\Vendor\Model\ResourceModel;
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
class Training4_Vendor2Product extends AbstractDb
{
protected function _construct()
{
$this->_init('training4_vendor2product','id');
}
}
\Training4\Vendor\Model\ResourceModel\Training4_Vendor2Product\Collection
<?php
namespace Training4\Vendor\Model\ResourceModel\Training4_Vendor2Product;
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
class Collection extends AbstractCollection
{
protected $_idFieldName = 'id';
protected function _construct()
{
$this->_init(\Training4\Vendor\Model\Training4_Vendor2Product::class,
\Training4\Vendor\Model\ResourceModel\Training4_Vendor2Product::class);
}
}
在\Training4\Vendor\Model\Training4_Vendor2Product,中,我已经扩展了Magento\Model\抽象模型,我不知道为什么会出现这种异常
发布于 2022-07-05 13:44:04
在di.xml中添加依赖项了吗?
<virtualType name="HelenOfTroy\Webinar\Model\ResourceModel\SpecificSpeakers\Grid\Collection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
<arguments>
<argument name="mainTable" xsi:type="string">training4_vendor2product</argument>
<argument name="resourceModel" xsi:type="string">Training4\Vendor\Model\ResourceModel\Training4_Vendor2Product</argument>
</arguments>
</virtualType>
https://stackoverflow.com/questions/72866935
复制相似问题