dt614037527 2016-10-11 18:22
浏览 46

不能在Magento2中使用带有自定义表的getCollection

I'm trying to follow Alan Storm's tutorial here. The code works fine when I try to insert or retrieve a single record, but it cracks when I use collections. I followed all steps he illustrated in the tutorial, which drives me crazy because only collections wouldn't work!!

public function __construct(
\Magento\Backend\App\Action\Context $context,
\Vendor\Mymodule\Model\ConfigurationsFactory $myClass
) {
    $this->myClass = $myClass;
    parent::__construct($context);
}

public function execute() {
 $todo = $this->myClass->create();

 $collection = $todo->getCollection();

 foreach($collection as $item)
  {
    var_dump('Item ID: ' . $item->getConfigId());
    var_dump($item->getData());
  }
exit;

}

This gives the following error:

Vendor\Mymodule\Model\Configurations does not extend \Magento\Framework\DataObject

The code for configurations model is as below

namespace Vendor\Mymodule\Model;
use Magento\Framework\Model\AbstractModel;

class Configurations extends AbstractModel
{
    protected function _construct()
    {
        $this->_init('Vendor\Mymodule\Model\ResourceModel\Configurations');
    }
}

ResourceModel

namespace Vendor\Mymodule\Model\ResourceModel;
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;

class Configurations extends AbstractDb
{
    protected function _construct()
    {
        $this->_init('vendor_configurations','config_id');
    }
}

Collection

namespace Vendor\Mymodule\Model\ResourceModel\Configurations;

class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
    protected function _construct()
    {
        $this->_init('
             Vendor\Mymodule\Model\Configurations',
            'Vendor\Mymodule\Model\ResourceModel\Configurations');
    }
}

any hints would be really appreciated. Thanks

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog