首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >不扩展\Magento\Framework\DataObject

不扩展\Magento\Framework\DataObject
EN

Stack Overflow用户
提问于 2022-07-05 09:20:59
回答 1查看 257关注 0票数 0

当我放弃model.Here时,我有例外--这是一个例外:

代码语言:javascript
运行
复制
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

代码语言:javascript
运行
复制
<?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

代码语言:javascript
运行
复制
<?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

代码语言:javascript
运行
复制
<?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\抽象模型,我不知道为什么会出现这种异常

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-07-05 13:44:04

在di.xml中添加依赖项了吗?

代码语言:javascript
运行
复制
<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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72866935

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档