O'Reilly logo

Magento 2 Development Cookbook by Bart Delvaux

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating a flat table with models

When you want to save data in a module, you may want to store that in a custom entity. That entity needs a database table and a model that talks with that database table.

We will create a subscriptions entity where we can store subscriptions.

Getting ready

In this recipe, we will extend the module of Chapter 4, Creating a Module, with an entity with a database table. Make sure you have the starter files for this recipe installed.

How to do it...

In the next steps, we will learn how we can add entities to an existing module:

  1. When installing a new entity, we have to create a resource model. We can do this by creating the file app/code/Packt/HelloWorld/Model/ResourceModel/Subscription.php with the following content:
    <?php ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required