I followed the instructions from the Accepted Answer of this question to create a model and model resource file.
Company/Project/Model/Album.php
<?php
namespace Company\Project\Model;
class Album extends \Magento\Framework\Model\AbstractModel {
public function __construct(
\Magento\Framework\Model\Context $context,
\Magento\Framework\Registry $registry,
\Psr\Log\LoggerInterface $logger,
\Magento\Framework\Model\Resource\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
) {
$this->_logger = $logger;
$this->_logger->addInfo("SO WE CAN ACTUALLY GET INTO THE MODEL FILE");
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
}
public function _construct() {
$this->_init('Company\Project\Model\Resource\Album');
}
}
Company/Project/Model/Resource/Album.php
<?php
namespace Company\Project\Model\Resource;
class Album extends \Magento\Framework\Model\Resource\Db\AbstractDb {
public function _construct() {
$this->_init('px_product_albums', 'id');
}
}
Company/Project/Helper/Data.php - This is where I'm getting the error
<?php
class Data extend \Magento\Framework\App\Helper\AbstractHelper {
.....
protected $pageFactory;
public function __construct(
....
\Magento\Cms\Model\PageFactory $pageFactory
)
......
function whereStuffIsHappening() {
.....
$albumId = WeHaveTheValue;
$productId = WeHaveThisValueToo;
$album = $this->pageFactory->create('Company\Project\Model\Album');
$this->_logger->addInfo("Album code is alright");
$album->setProductId($product->getId())->setPixleeAlbumId($albumId);
$album->save();
$this->_logger->addInfo("ALBUM ID SUCCESSFULLY SAVED");
It seems like the following line doesn't execute. I get a 503 (Service Unavailable).
$album = $this->pageFactory->create('Company\Project\Model\Album');
Some of the things that I have tried
The strange thing is that I never see "SO WE CAN ACTUALLY GET INTO THE MODEL FILE" logged (Its a print statement in the Model file). Which leads me to think that the model is not being initiated. But I could be wrong.
Help?