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
any help would be really appreciated.
You already have the error message:
Vendor\Mymodule\Model\Configurations does not extend \Magento\Framework\DataObject
Only models which extend \Magento\Framework\DataObject can have collections. So, first step is to make your model extend that class (or better: extend \Magento\Framework\Model\AbstractModel which again extends the mentioned class as in Alan Storm's example). If you get more errors, you should upload the whole module.
Hello,
I already extended my Model with \Magento\Framework\Model\AbstractModel but still I am getting same error. My model code is
class Post extends AbstractModel implements PostInterface, IdentityInterface {Please guide me....