Create a model in Magento
Learn how to create a Magento 2 model class for a blog post entity using AbstractModel.
Lesson Content
We’re going to set up all of our backend database layer files now in their entirety.
A model represents any data entity in Magento. It doesn’t necessarily need to be linked to a database either, as a model can represent any kind of data entity.
Let us create a model by creating a Model folder in our module directory. Then we will create a file for the name of our model. Since our first model is a post, we will create a file named Post.php.
Let’s open up our PHP tag and declare strict types, set the namespace for this new class to Macademy\Blog\Model, then create this class named...
Join the discussion!
Comments
Want to comment on this lesson?
Enroll in this course to leave comments.