首页  >  问答  >  正文

不扩展\Magento\Framework\DataObject

我在创建模型时遇到异常。这是该异常:

1 exception(s):
Exception #0 (InvalidArgumentException): Training4VendorModelTraining4_Vendor2Product does not extend MagentoFrameworkDataObject

Exception #0 (InvalidArgumentException): Training4VendorModelTraining4_Vendor2Product does not extend MagentoFrameworkDataObject

Magento 版本是 2.4.4 Training4VendorModelTraining4_Vendor2Product

<?php


namespace Training4VendorModel;


use MagentoFrameworkModelAbstractModel;

class Training4_Vendor2Product extends AbstractModel
{
    const vendor_id='id';

    protected $_idFieldName  = self::vendor_id;

    protected function _construct()
    {
        $this->_init(Training4VendorModelResourceModelTraining4_Vendor2Product::class);
    }
}

Training4VendorModelResourceModelTraining4_Vendor2Product

<?php


namespace Training4VendorModelResourceModel;


use MagentoFrameworkModelResourceModelDbAbstractDb;

class Training4_Vendor2Product extends AbstractDb
{

    protected function _construct()
    {
        $this->_init('training4_vendor2product','id');
    }
}

Training4VendorModelResourceModelTraining4_Vendor2ProductCollection

<?php


namespace Training4VendorModelResourceModelTraining4_Vendor2Product;


use MagentoFrameworkModelResourceModelDbCollectionAbstractCollection;

class Collection extends AbstractCollection
{
    protected $_idFieldName = 'id';

    protected function _construct()
    {
        $this->_init(Training4VendorModelTraining4_Vendor2Product::class,
            Training4VendorModelResourceModelTraining4_Vendor2Product::class);
    }
}

在 Training4VendorModelTraining4_Vendor2Product 中,我已经扩展了 MagentoFrameworkModelAbstractModel,我不知道为什么会发生该异常

P粉026665919P粉026665919309 天前603

全部回复(1)我来回复

  • P粉953231781

    P粉9532317812024-01-08 00:33:25

    您是否在 di.xml 中添加了依赖项

    
        
            training4_vendor2product
            Training4\Vendor\Model\ResourceModel\Training4_Vendor2Product
        
    

    回复
    0
  • 取消回复