Video Lesson: Implement a DTO into a model in Magento

Implement a DTO into a model in Magento

This is premium content

Only available to enrolled or University students.
Join today to unlock all lessons in this course.

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
{...

Premium content

Enroll to unlock the full content and all course materials.

Maggie

Hey, I'm Maggie! πŸ‘‹

Ask me anything.

Want to chat with Maggie?

Enroll in this course for AI tutor access.

Comments

Join the discussion!

Comments

Want to comment on this lesson?

Enroll in this course to leave comments.