Implement a DTO into a model in Magento
Implement a DTO interface in a Magento 2 model using PostInterface constants and getData setData methods.
Lesson Content
Before we create a repository interface, we can have our model implement our newly created DTO interface. Since we now have a Post data object defined, our model should conform to it. Weβll do that by making our model implement this new DTO interface.
Letβs open up our Post model, and tack on an implements PostInterface:
<?php
declare(strict_types=1);
namespace Macademy\Blog\Model;
use Macademy\Blog\Api\Data\PostInterface;
use Magento\Framework\Model\AbstractModel;
class Post extends AbstractModel implements PostInterface
{...
Join the discussion!
Comments
Want to comment on this lesson?
Enroll in this course to leave comments.