Magento 2 - 保存自定义实体

时间:2017-10-17 16:40:46

标签: magento magento2 magento2-extensions

我刚刚在mage2gen创建了一个自定义实体,链接如下: https://mage2gen.com/download/195a0734-62bc-4b0d-9fb4-b352878a9c2e.tar https://mage2gen.com/load/195a0734-62bc-4b0d-9fb4-b352878a9c2e

虽然我在保存这些实体方面遇到了问题,但我不知道该怎么做,我已经尝试了很多我发现的解决方案,有人能帮帮我吗?

构造

public function __construct(
    \Magento\Framework\App\RequestInterface $request,
    \Trezo\Sigep\Helper\Data $helper,
    \Magento\Framework\ObjectManagerInterface $objectmanager,
    \Trezo\Sigep\Model\SigepwebPostcardObjectFactory $factory,
    \Trezo\Sigep\Model\SigepwebPostcardObjectRepository $repository
)

我试过了:

$object = $this->factory->create();
$object->addData($data);
$object->save();

$object = $this->factory->create();
$object->addData($data);
$this->repository->save($object);

$object =  $this->_objectManager->create('Trezo\Sigep\Model\SigepwebPostcardObject');
$object->addData($data);
$object->save();

0 个答案:

没有答案